Thursday, 4 October 2012

Checking Keyword and Identifier

 #include<stdio.h>
#include<conio.h>
#include<string.h>



void main()
{
again:


int i,flag=0,m;
char s[32][10]={"auto","break","case","char","const","continue","default",
"do","double","else","enum","extern","float","for","goto","if","int",
"long","register","return","short","signed","sizeof","static","struct",
"switch","typedef","union","unsigned","void","volatile","while"},st[10];
clrscr();
  printf("Checking Keyword and Identifier \n") ;
printf("\n Enter the string :");
gets(st);

for(i=0;i<32;i++)
{
m=strcmp(st,s[i]);
if(m==0)
flag=1;
}
if(flag==0) {


if((st[0]>'0' && st[0]<='9') || (st[0]>='a'&& st[0]<='z') || (st[0]>='A')&& st[0]<='Z'|| st[0]>='_')
{
    if(st[0]='0' && st[0]<='9')
    {
    printf("\n\tIdentifier is not valid");
    }
    else
    {
printf("\n \tThis is identifier");
}

}


}
else
printf("\n\tThis is a keyword\n");


getch();
 goto again;
}


Written by 'Shojib'

No comments:

Post a Comment