Lexical Analyzer in C eroor -


i want source c have erorr in program

#include<stdio.h>  #include<ctype.h>  #include<string.h>  void keyw(char *p);  int i=0,id=0,kw=0,num=0,op=0;  char keys[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"};  main()  {  	char ch,str[25],seps[15]=" \t\n,;(){}[]#\"<>",oper[]="!%^&*-+=~|.<>/?";  	int j;  	char fname[50];  	file *f1;  	//clrscr();  printf("enter file path (drive:\\fold\\filename)\n");  scanf("%s",fname);  f1 = fopen(fname,"r");  //f1 = fopen("input","r");  	if(f1==null)  	{  	 printf("file not found");  	 exit(0);  	}  	while((ch=fgetc(f1))!=eof)  	{  for(j=0;j<=14;j++)  {  if(ch==oper[j])  {  printf("%c operator\n",ch);  op++;  str[i]='\0';  keyw(str);  }  }  for(j=0;j<=14;j++)  {  if(i==-1)  break;  if(ch==seps[j])  {  if(ch=='#')  {  while(ch!='>')  {  printf("%c",ch);  ch=fgetc(f1);  }  printf("%c header file\n",ch);  i=-1;  break;  }  if(ch=='"')  {   {  ch=fgetc(f1);  printf("%c",ch);  }while(ch!='"');  printf("\b argument\n");  i=-1;  break;  }  str[i]='\0';  keyw(str);  }  }  if(i!=-1)  {  str[i]=ch;  i++;  }  else  i=0;  	}  printf("keywords: %d\nidentifiers: %d\noperators: %d\nnumbers: %d\n",kw,id,op,num);  //getch();  }  void keyw(char *p)  {  int k,flag=0;  for(k=0;k<=31;k++)  {  if(strcmp(keys[k],p)==0)  {  printf("%s keyword\n",p);  kw++;  flag=1;  break;  }  }  if(flag==0)  {  if(isdigit(p[0]))  {  printf("%s number\n",p);  num++;  }  else  {  //if(p[0]!=13&&p[0]!=10)  if(p[0]!='\0')  {  printf("%s identifier\n",p);  id++;  }  }  }  i=-1;  }

eroor

c:\users\jurs\documents\abc\main.cpp in function 'int main()':

13 27 c:\users\jurs\documents\abc\main.cpp [error] initializer-string array of chars long [-fpermissive]

25 9 c:\users\jurs\documents\abc\main.cpp [error] 'exit' not declared in scope

28 c:\users\jurs\documents\abc\makefile.win recipe target 'main.o' failed

try changing

seps[15]=" \t\n,;(){}[]#\"<>" 

to

seps[16]=" \t\n,;(){}[]#\"<>" 

also try changing

main() 

to

int main() 

and maybe change

exit(0); 

to

return 0; 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -