i am try to store the input data and check which is keyword but it is working both Identifier and Keyword. i want it will show different section identifier are show identifier and keyword are show keyword section. see this code: Plese help me anyone. i have upload the output picture here and mark this what i want.Output
#include<stdio.h>
#include<string.h>
void lexicalAnalyzerk(char s[]);
int isIdent(char ch);
int isAlpha(char ch);
int isDisit(char ch);
char A[100], ident[100][32];
int kyi=0, kyj=0, idi=0, idj=0, i=0, j=0;
char *key[32]={"char","int","float","double","short","long","signed","unsigned","if","else","for","do","while",
"switch","case","void","break","continue","return","default","goto","static","sizeof","typedef",
"auto","const","struct","enum","volatile","extern","register","union"};
int main()
{
gets(A);
lexicalAnalyzerk(A);
return 0;
}
void lexicalAnalyzerk(char s[])
{
while(s[i])
{
if(isIdent(s[i]))
{
while(isIdent(s[i]))
{
ident[idi][idj] = s[i];
idj++;
i++;
}
ident[idi][idj] = '\0';
idi++;
idj = 0;
}
else
i++;
}
printf("\nThis Are Identifier:\n");
for(i=0; i<=idi; i++)
{
printf("%s\n", ident[i]);
}
printf("\nThis Are Keyword:\n");
for (j=0; j<=idi; j++) {
for (i=0; i<31; i++) {
if(strcmp(key[i], ident[j])==0){
printf("%s\n", key[i]);
}
}
}
}
int isIdent(char ch)
{
if(isAlpha(ch) || isDisit(ch) || ch == '_')
return 1;
else
return 0;
}
int isAlpha(char ch)
{
if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
return 1;
else
return 0;
}
int isDisit(char ch)
{
if(ch>='0' && ch<='9')
return 1;
else
return 0;
}