#include #include #include #include void main(){ FILE *input = fopen("lex.txt","r"); char buffer[100]; int n=0,i; do { char c = fgetc(input); if(c=='+'||c=='-'||c=='*'||c=='/'||c=='%'||c=='=') { if(strncmp("int",buffer,n)==0||strncmp("float",buffer,n)==0||strncmp("if",buffer,n)==0||strncmp("else",buffer,n)==0||strncmp("printf",buffer,n)==0) { printf("%s is a keyword\n",buffer); for(i=0;i<10;i++) { buffer[i]='\0'; } n=0; } else { printf("%s is a identifier\n",buffer); for(i=0;i<10;i++) { buffer[i]='\0'; } n=0; } printf("%c is an operator\n",c); } else if(isalnum(c)) { buffer[n++]=c; } if(feof(input)) break; }while(1); printf("%s is a identifier\n\n",buffer); }