fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. void main()
  4. {
  5. char string[50];
  6. int flag,count=o;
  7.  
  8. printf("The grammar is: S->aS, S->Sb, S->ab\n");
  9. printf("Enter the string to be checked:\n");
  10. gets(string);
  11. if(string[0]=='a')
  12. {
  13. flag=0;
  14. for (count=1;string[count-1]!='\0';count++)
  15. {
  16. if(string[count]=='b')
  17. {
  18. flag=1;
  19. continue;
  20. }
  21. else if((flag==1)&&(string[count]=='a'))
  22. {
  23. printf("The string does not belong to the specified grammar");
  24. break;
  25. }
  26. else if(string[count]=='a')
  27. {
  28. continue;
  29. }
  30. else if(flag==1)&&(string[count]='\0'))
  31. {
  32. printf("String accepted…..!!!!");
  33. break;
  34. }
  35. else
  36. {
  37. printf("String not accepted");
  38. }
  39. }
  40. }
  41.  
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main()
      ^~~~
prog.c: In function ‘main’:
prog.c:6:17: error: ‘o’ undeclared (first use in this function)
  int flag,count=o;
                 ^
prog.c:6:17: note: each undeclared identifier is reported only once for each function it appears in
prog.c:10:2: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration]
  gets(string);
  ^~~~
prog.c:30:22: error: expected identifier before ‘(’ token
    else if(flag==1)&&(string[count]='\0'))
                      ^
prog.c:30:4: warning: this ‘else’ clause does not guard... [-Wmisleading-indentation]
    else if(flag==1)&&(string[count]='\0'))
    ^~~~
prog.c:30:42: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘else’
    else if(flag==1)&&(string[count]='\0'))
                                          ^
prog.c:30:42: error: expected statement before ‘)’ token
prog.c:35:4: error: ‘else’ without a previous ‘if’
    else
    ^~~~
stdout
Standard output is empty