LOGIC: 1. Read the input Expression 2. Check whether input is alphabet or digits then store it as identifier 3. If the input is is operator store it as symbol 4. Check the input for keywords
#include
#include
#include
void keyword(char[]);
void main()
{
FILE *f1,*f2,*f3;
char c,str[10],st1[10];
int num[100],lineno=0,tokenvalue=0,i=0,j=0,k=0;
clrscr();
printf("\nEnter the c program\n");
f1=fopen("input.txt","w");
while((c=getchar())!=EOF)
putc(c,f1);
fclose(f1);
f1=fopen("input.txt","r");
f2=fopen("identifier.txt","w");
f3=fopen("specialchar.txt","w");
while((c=getc(f1))!=EOF)
{
if(isdigit(c))
{
tokenvalue=c-48;
c=getc(f1);
while(isdigit(c))
{
tokenvalue=tokenvalue*10+(c-48);
c=getc(f1);
}
num[i++]=tokenvalue;
ungetc(c,f1);
}
else if(isalpha(c))
{
putc(c,f2);
c=getc(f1);
while(isdigit(c)||isalpha(c)||c=='_'||c=='$')
{
putc(c,f2);
c=getc(f1);
}
putc(' ',f2);
ungetc(c,f1);
}
else if(c==' '||c=='\t') printf(" ");
else if(c=='\n')
lineno++;
else
putc(c,f3);
}
fclose(f2);
fclose(f3);
fclose(f1);
printf("\nThe numbers in the program are:");
for(j=0;j
OUTPUT Enter the c program int main() { int a=10,20; char ch; float f; }^Z The numbers in the program are: 10 20 The keywords and identifiersare: int is a keyword main is an identifier int is a keyword a is an identifier char is a keyword ch is an identifier float is a keyword f is an identifier Special characters are ( ) { = , ; ; ; } Total no. of lines are:5