ad

Tuesday, 3 January 2012

programme to find if the entered string is key word or not in c

//PROGRAM FOR CHECKING A STRING WHETHER KEYWORD OR NOT
#include< conio.h>
#include< stdio.h>
#include< string.h>
#include< process.h>
void read(char* s)
{
printf("\n\nEnter the keyword\n\n\t\t");
scanf("%s",s);
}
void check(char* s)
{
int i,flag=0;
char key[32][20]={"volatile","const","void","auto","static","break","case","continue","char","double","default","enum","extern","float","goto","int","if","for","else","register","struct","switch","union","signed","unsigned","while","sizeof","return","short","do","typedef","long"};
for(i=0;i<32;i++)
{
if(strcmp(s,key[i])==0)
flag=1;
}
if(flag==1)
printf("\n\t\t......It is a keyword.............");
else
printf("\n\t\t......It is not a keyword......");
}
void main()
{
char ch,s[15];
clrscr();
printf("\n\n\t\t***KEYWORD OR NOT***\n\n");
do
{
read(s);
check(s);
printf("\n\n\t\tDo you want to continue?[y/n]\n");
ch=getch();
}while(ch=='Y'||ch=='y');
exit(0);
getch();
}

No comments:

Post a Comment