fork download
  1. #include<string.h>
  2. #include<ctype.h>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. void keyword(char str[10])
  6. {
  7. if(strcmp("for",str)==0||strcmp("while",str)==0||strcmp("do",str)==0||strcmp("int",str)==0||str
  8. cmp("float",str)==0||strcmp("char",str)==0||strcmp("double",str)==0||strcmp("printf",str)==0||
  9. strcmp("switch",str)==0||strcmp("case",str)==0)
  10. printf("\n%s is a keyword",str);
  11. else
  12. printf("\n%s is an identifier",str);
  13. }
  14. void main()
  15. {
  16. FILE *f1,*f2,*f3;
  17. char c,str[10],st1[10];
  18. int num[100],lineno=0,tokenvalue=0,i=0,j=0,k=0;
  19. f1=fopen("input","r");
  20. f2=fopen("identifier","w");
  21. f3=fopen("specialchar","w");
  22. while((c=getc(f1))!=EOF)
  23. { if(isdigit(c))
  24. {
  25. tokenvalue=c-'0';
  26. c=getc(f1);
  27. while(isdigit(c))
  28. {
  29. tokenvalue*=10+c-'0';
  30. c=getc(f1);
  31. }
  32. num[i++]=tokenvalue;
  33. ungetc(c,f1);
  34. }
  35. else
  36. if(isalpha(c))
  37. {
  38. putc(c,f2);
  39. c=getc(f1);
  40. while(isdigit(c)||isalpha(c)||c=='_'||c=='$')
  41. {
  42. putc(c,f2);
  43. c=getc(f1);
  44. }
  45. putc(' ',f2);
  46. ungetc(c,f1);
  47. }
  48. else
  49. if(c==' '||c=='\t')
  50. printf(" ");
  51. else
  52. if(c=='\n')
  53. lineno++;
  54. else
  55. putc(c,f3);
  56. }
  57. fclose(f2);
  58. fclose(f3);
  59. fclose(f1);
  60. printf("\n the no's in the program are:");
  61. for(j=0;j<i;j++)
  62. printf("\t%d",num[j]);
  63. printf("\n");
  64. f2=fopen("identifier","r");
  65. k=0;
  66. printf("the keywords and identifier are:");
  67. while((c=getc(f2))!=EOF)
  68. if(c!=' ')
  69. str[k++]=c;
  70. else {
  71. str[k]='\0';
  72. keyword(str);
  73. k=0;
  74. }
  75. fclose(f2);
  76. f3=fopen("specialchar","r");
  77. printf("\n Special Characters are");
  78. while((c=getc(f3))!=EOF)
  79. printf("\t%c",c);
  80. printf("\n");
  81. fclose(f3);
  82. printf("Total no of lines are:%d",lineno);
  83. }
  84.  
  85.  
Success #stdin #stdout #stderr 0.03s 6844KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/UfbTQE/prog:84:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit