fork download
  1. #include<string.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #pragma warning(disable : 4996)
  5.  
  6. bool check[512];
  7. char First[512][512];
  8.  
  9. char *first(char target[512][512],bool check[],int n) {
  10. check[n] = true;
  11. int i=2,k=0,m=0;
  12. char rule[512][512];
  13. while (target[n][i]!='\0') {//拆解'|'
  14. if (target[n][i] != '|') {
  15. rule[m][k] = target[n][i];
  16. k++;
  17. }
  18. else {
  19. rule[m][k] = '\0';
  20. m++;
  21. k = 0;
  22. }
  23. i++;
  24. }
  25. rule[m][k] = '\0';
  26. int firstnum = 0;
  27. for (int j = 0; j <= m; j++) {
  28. int l = 0;
  29. while (rule[j][l] != '\0') {
  30. if (rule[j][l] > 'z' || rule[j][l] < 'a') {
  31.  
  32. First[n][firstnum] = rule[j][l];
  33. firstnum++;
  34. break;
  35. }
  36. else {
  37. int num = 0;
  38. while (target[num][0] != rule[j][l]) {
  39. num++;
  40. continue;
  41. }
  42. strcat(First[n],first(target, check, num));
  43.  
  44. }
  45. l++;
  46. }
  47. }
  48. return First[n];
  49.  
  50. }
  51.  
  52.  
  53. int main() {
  54.  
  55. char input[512][512];
  56. int RuleNum=0;
  57. do {
  58. gets_s(input[RuleNum]);
  59. check[RuleNum] = false;
  60. RuleNum++;
  61. } while (strcmp(input[RuleNum-1], "END_OF_GRAMMAR") != 0);
  62. int n = 0;
  63. while (n < RuleNum-1) {
  64. if (check[n] == false) {
  65. first(input, check,n);
  66. }
  67. n++;
  68. }
  69.  
  70. printf("%d", RuleNum);
  71.  
  72. system("pause");
  73. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:4: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
 
prog.c:6:1: error: unknown type name ‘bool’; did you mean ‘_Bool’?
 bool check[512];
 ^~~~
 _Bool
prog.c:9:35: error: unknown type name ‘bool’; did you mean ‘_Bool’?
 char *first(char target[512][512],bool check[],int n) {
                                   ^~~~
                                   _Bool
prog.c: In function ‘main’:
prog.c:58:3: warning: implicit declaration of function ‘gets_s’; did you mean ‘getenv’? [-Wimplicit-function-declaration]
   gets_s(input[RuleNum]);
   ^~~~~~
   getenv
prog.c:59:20: error: ‘false’ undeclared (first use in this function); did you mean ‘fclose’?
   check[RuleNum] = false;
                    ^~~~~
                    fclose
prog.c:59:20: note: each undeclared identifier is reported only once for each function it appears in
prog.c:65:4: warning: implicit declaration of function ‘first’ [-Wimplicit-function-declaration]
    first(input, check,n);
    ^~~~~
prog.c:72:2: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result [-Wunused-result]
  system("pause");
  ^~~~~~~~~~~~~~~
stdout
Standard output is empty