fork download
  1. #include<string.h>
  2. #include<conio.h>
  3. #include<ctype.h>
  4. #include<stdio.h>
  5. void main(*f1)
  6. {
  7. FILE *f1;
  8. char c,str[10];
  9. int lineno=1,num=0,i=0;
  10. clrscr();
  11. printf("\nEnter the c program\n");
  12. f1=fopen("input.txt","w");
  13. while((c=getchar())!=EOF)
  14. putc(c,f1);
  15. fclose(f1);
  16. f1=fopen("input.txt","r");
  17. while((c=getc(f1))!=EOF) // TO READ THE GIVEN FILE
  18. {
  19. if(isdigit(c)) // TO RECOGNIZE NUMBERS
  20. {
  21. num=c-48;
  22. c=getc(f1);
  23. while(isdigit(c))
  24. {
  25. num=num*10+(c-48);
  26. c=getc(f1);
  27. }
  28. printf("%d is a number \n",num);
  29. ungetc(c,f1);
  30. }
  31. else if(isalpha(c)) // TO RECOGNIZE KEYWORDS AND IDENTIFIERS
  32. {
  33. str[i++]=c;
  34. c=getc(f1);
  35. while(isdigit(c)||isalpha(c)||c=='_'||c=='$')
  36. {
  37. str[i++]=c;
  38. c=getc(f1);
  39. }
  40. str[i++]='\0';
  41. if(strcmp("for",str)==0||strcmp("while",str)==0||strcmp("do",str)==0||
  42. strcmp("int",str)==0||strcmp("float",str)==0||strcmp("char",str)==0||
  43. strcmp("double",str)==0||strcmp("static",str)==0||
  44. strcmp("switch",str)==0||strcmp("case",str)==0) // TYPE 32 KEYWORDS
  45. printf("%s is a keyword\n",str);
  46. else
  47. printf("%s is a identifier\n",str);
  48. ungetc(c,f1);
  49. i=0;
  50. }
  51. else if(c==' '||c=='\t') // TO IGNORE THE SPACE
  52. printf("\n");
  53. else if(c=='\n') // TO COUNT LINE NUMBER
  54. lineno++;
  55. else // TO FIND SPECIAL SYMBOL
  56. printf("%c is a special symbol\n",c);
  57. }
  58. printf("Total no. of lines are: %d\n",lineno);
  59. fclose(f1);
  60. getch();
  61. }
  62.  
  63.  
Success #stdin #stdout #stderr 0.02s 6856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/vLfUJs/prog:62:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit