//kataria arvind//
//lexical analysis//
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
int i,j;
char kw[10][10]={"int","float","char"};
char array[100];
char oper[4]={'=','+','-','*'};
clrscr();
fp=fopen("test1.c","r");
printf("\n keyword:");
while(!feof(fp))
{
fscanf(fp,"%s",array);
for(i=0;i<=2;i++)
{
if(strcmp(kw[i],array)==0)
{
printf("%s",array);
}
}
}
fclose(fp);
fp=fopen("test1.c","r");
printf("\n operator:");
while(!feof(fp))
{
array[0]=fgetc(fp);
for(i=0;i<=4;i++)
{
if(array[0]==oper[i])
{
printf("%c",oper[i]);
}
}
}
fclose(fp);
getch();
}
No comments:
Post a Comment