C Program to Check Whether Entered String is Keyword or Not?
we know that ANSI C has 32 keyword. actually Keyword are reserved words which predefined in any language. we can not use further these words in program because they have special meaning.if i use these words for our purpose then our compiler get confused to use these words so that we can not use keyword as variable name and etc.
C Program:
#include<stdio.h> #include<conio.h> #include<string.h> void main() { char keyword[32][10]={"auto","double","int","struct","break","else","long", "switch","case","enum","register","typedef","char", "extern","return","union","const","float","short", "unsigned","continue","for","signed","void","default", "goto","sizeof","voltile","do","if","static","while"} ; char string[10]; int flag=0,i; printf("enter any string:"); gets(string); for(i=0;i<32;i++) { if(strcmp(string,keyword[i])==0) { flag=1; } } if(flag==1) printf("%s is a keyword",string); else printf("%s is not a keyword",string); getch(); }
No comments