Se connecter avec
S'enregistrer | Connectez-vous

pb programme de conjugaison et fgets

Dernière réponse : dans Programmation

Bonjour! j'essaye actuellement de faire un programme qui fasse les conjugaison de verbes.
Cependant je rencontre des erreurs. J'ai changé la fonction gets par fgets pour récupérer la valeur saisie mais je n'arrive pas à tester le retour. j'ai comme message d'erreur "undefined reference to flush". Si vous avez une idée merci!
  1. int viregulier(char *input)
  2. {
  3. FILE *fptr;
  4. int i=0;
  5. char buffer;
  6. char *extension=".txt";
  7. char nomfichier[100];
  8.  
  9. for(i=0;i<sizeof(irregulier)/sizeof(char*);i++)
  10. {
  11. if(strcmp(input,*(irregulier+i))==0)
  12. {
  13. strcpy(nomfichier,input);
  14. strcat(nomfichier,extension);
  15. printf("%s",nomfichier);
  16. if((fptr = fopen(nomfichier, "rt")) == NULL)
  17. {
  18. printf("Désolé nous n'avons pas ce verbe");
  19. return 1;
  20. }
  21. while((buffer = fgetc(fptr))!=EOF)
  22. putchar(buffer);
  23. fclose(fptr);
  24. return 1;
  25. }
  26. }
  27. return 0;
  28. };
  29.  
  30. main()
  31. {
  32.  
  33. char *er = "er";
  34. char *re = "re";
  35. char *ir = "ir";
  36.  
  37. char input[200];
  38. char output[200];
  39. const char **ptrconjugaison;
  40.  
  41. char *ptr;
  42. char again = 0;
  43. int i=0,j=0;
  44.  
  45. while(again!='n' && again!='N')
  46. {
  47. printf("\nChoisissez un verbe à conjuguer : ");
  48.  
  49. if (fgets(input,sizeof input,stdin) != NULL)
  50. {
  51. if(!viregulier(input))
  52. {
  53. ptr = &input[strlen(input)-2];
  54.  
  55. if(strcmp(ptr,er)==0)
  56. ptrconjugaison = prem_conjugaison;
  57. else if(strcmp(ptr,re)==0)
  58. ptrconjugaison = deux_conjugaison;
  59. else if(strcmp(ptr,ir)==0)
  60. ptrconjugaison = trois_conjugaison;
  61. else
  62. {
  63. printf("Verbe incorrect");
  64. printf("\nChoisissez un autre verbe (N pour quitter) :");
  65. again = getchar();
  66.  
  67. }
  68.  
  69. printf("\nInfinitif %s\n\n",ptr);
  70.  
  71. input[strlen(input)-2]='\0';
  72. strcpy(output,input);
  73. printf("\nPresent :\n");
  74. for(j=0;j<6;j++)
  75. printf("%10s %s\n",pronoms[j],input,*(ptrconjugaison++));
  76. printf("\nSubjonctif :\n");
  77. for(j=0;j<6;j++)
  78. printf("%10s %s\n",pronoms[j],input,*(ptrconjugaison++));
  79. printf("\nFutur :\n");
  80. for(j=0;j<6;j++)
  81. printf("%10s %s\n",pronoms[j],input,*(ptrconjugaison++));
  82. printf("\nConditionel :\n");
  83. for(j=0;j<6;j++)
  84. printf("%10s %s\n",pronoms[j],input,*(ptrconjugaison++));
  85. printf("\nImparfait :\n");
  86. for(j=0;j<6;j++)
  87. printf("%10s %s\n",pronoms[j],input,*(ptrconjugaison++));
  88. printf("\nPasse :\n");
  89. for(j=0;j<6;j++)
  90. printf("%10s %s\n",pronoms[j],input,*(ptrconjugaison++));
  91. printf("\nImparfait du Subjonctif :\n");
  92. for(j=0;j<6;j++)
  93. printf("%10s %s\n",pronoms[j],input,*(ptrconjugaison++));
  94. printf("\nParticipe Present :\n");
  95. for(j=0;j<4;j++)
  96. printf("%10s%s\n",input,*(ptrconjugaison++));
  97. printf("\nParticipe Passe :\n");
  98. for(j=0;j<4;j++)
  99. printf("%10s%s\n",input,*(ptrconjugaison++));
  100. }
  101. // =======================================
  102. printf("\n\nSaisissez un verbe (N pour quitter) :");
  103. again = getchar();
  104. fflush(stdin);
  105. }
  106. }
  107. printf("\nAu revoir!!\n\n");
  108. }

Autres pages sur : programme conjugaison fgets

Lassé par la pub ? Créez un compte

amin01 a dit :
Bonjour! j'essaye actuellement de faire un programme qui fasse les conjugaison de verbes.
Cependant je rencontre des erreurs. J'ai changé la fonction gets par fgets pour récupérer la valeur saisie mais je n'arrive pas à tester le retour. j'ai comme message d'erreur "undefined reference to flush". Si vous avez une idée merci!

Merci de poster du code un peu plus compilable que ça...

Project : Forums
Compiler : GNU GCC Compiler (called directly)
Directory : D:\dev\ed02\cb\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: main.c
main.c:2: warning: no previous prototype for 'viregulier'
main.c: In function `viregulier':
main.c:3: error: `FILE' undeclared (first use in this function)
main.c:3: error: (Each undeclared identifier is reported only once
main.c:3: error: for each function it appears in.)
main.c:3: error: `fptr' undeclared (first use in this function)
main.c:6: warning: initialization discards qualifiers from pointer target type
main.c:9: error: `irregulier' undeclared (first use in this function)
main.c:11: error: implicit declaration of function `strcmp'
main.c:11: warning: nested extern declaration of `strcmp'
<internal>:0: warning: redundant redeclaration of 'strcmp'
main.c:13: error: implicit declaration of function `strcpy'
main.c:13: warning: nested extern declaration of `strcpy'
<internal>:0: warning: redundant redeclaration of 'strcpy'
main.c:14: error: implicit declaration of function `strcat'
main.c:14: warning: nested extern declaration of `strcat'
<internal>:0: warning: redundant redeclaration of 'strcat'
main.c:15: error: implicit declaration of function `printf'
main.c:15: warning: nested extern declaration of `printf'
<internal>:0: warning: redundant redeclaration of 'printf'
main.c:16: error: implicit declaration of function `fopen'
main.c:16: warning: nested extern declaration of `fopen'
main.c:16: error: `NULL' undeclared (first use in this function)
main.c:21: error: implicit declaration of function `fgetc'
main.c:21: warning: nested extern declaration of `fgetc'
main.c:21: error: `EOF' undeclared (first use in this function)
main.c:22: error: implicit declaration of function `putchar'
main.c:22: warning: nested extern declaration of `putchar'
<internal>:0: warning: redundant redeclaration of 'putchar'
main.c:23: error: implicit declaration of function `fclose'
main.c:23: warning: nested extern declaration of `fclose'
main.c: At top level:
main.c:31: warning: return type defaults to `int'
main.c: In function `main_':
main.c:33: warning: initialization discards qualifiers from pointer target type
main.c:34: warning: initialization discards qualifiers from pointer target type
main.c:35: warning: initialization discards qualifiers from pointer target type
main.c:47: warning: nested extern declaration of `printf'
<internal>:0: warning: redundant redeclaration of 'printf'
main.c:49: error: implicit declaration of function `fgets'
main.c:49: warning: nested extern declaration of `fgets'
main.c:49: error: `stdin' undeclared (first use in this function)
main.c:49: error: `NULL' undeclared (first use in this function)
main.c:53: error: implicit declaration of function `strlen'
main.c:53: warning: nested extern declaration of `strlen'
<internal>:0: warning: redundant redeclaration of 'strlen'
main.c:55: warning: nested extern declaration of `strcmp'
<internal>:0: warning: redundant redeclaration of 'strcmp'
main.c:56: error: `prem_conjugaison' undeclared (first use in this function)
main.c:58: error: `deux_conjugaison' undeclared (first use in this function)
main.c:60: error: `trois_conjugaison' undeclared (first use in this function)
main.c:65: error: implicit declaration of function `getchar'
main.c:65: warning: nested extern declaration of `getchar'
main.c:72: warning: nested extern declaration of `strcpy'
<internal>:0: warning: redundant redeclaration of 'strcpy'
main.c:75: error: `pronoms' undeclared (first use in this function)
main.c:75: warning: too many arguments for format
main.c:78: warning: too many arguments for format
main.c:81: warning: too many arguments for format
main.c:84: warning: too many arguments for format
main.c:87: warning: too many arguments for format
main.c:90: warning: too many arguments for format
main.c:93: warning: too many arguments for format
main.c:103: warning: nested extern declaration of `getchar'
main.c:65: warning: redundant redeclaration of 'getchar'
main.c:65: warning: previous implicit declaration of 'getchar' was here
main.c:104: error: implicit declaration of function `fflush'
main.c:104: warning: nested extern declaration of `fflush'
main.c:107: warning: nested extern declaration of `printf'
<internal>:0: warning: redundant redeclaration of 'printf'
main.c:43: warning: unused variable `i'
main.c:108:2: warning: no newline at end of file
Process terminated with status 1 (0 minutes, 1 seconds)
25 errors, 44 warnings

bonjour Emmanuel , désolé pour la compilation mais effectivement je me suis trompé de programme à force de faire des version bêta.
bon je sais c'est pas génial mais j'utilise finalement un scanf qui à mon niveau est plus facile car je ne sais pas comment tester le retour. j'ai regarder sur ton site et après plusieurs tentatives je n'ai pas réussi.
Voici ce que j'ai fait, cela fonctionne, il faut maintenant que je le complexifie pour le j et le j' par exemple.
le probleme que je vais rencontrer également c'est que pour chaque verbe "irregulier" je vais devoir faire un fichier texte.

  1. #include<stdio.h>
  2.  
  3. #include<string.h>
  4.  
  5. const char *irregulier[]={"faire","pouvoir","avoir","etre","prendre","devoir","permettre",
  6.  
  7. "mettre","aller","voir","dire","savoir","joindre","venir",
  8.  
  9. "vouloir","attendre","envoyer","transmettre","partir","courir","finir",
  10.  
  11. "aimer","tenir","appeler","asseoir","taire","manger","choisir",
  12.  
  13. "connaitre","comprendre","sortir","sentir","croire","recevoir","plaire",
  14.  
  15. "ecrire","mourir","essayer","boire","jouer","rendre","lire",
  16.  
  17. "passer","repondre","jeter","reussir","suivre","donner","convenir","etablir"};
  18.  
  19.  
  20.  
  21.  
  22.  
  23. const char *prem_conjugaison[]={ "e","es","e","ons","ez","ent",
  24.  
  25. "e","es","e","ions","iez","ent",
  26.  
  27. "erai","eras","era","erons","erez","eront",
  28.  
  29. "erais","erais","erait","erions","eriez","eraient",
  30.  
  31. "ais","ais","ait","ions","iez","aient",
  32.  
  33. "ai","as","a","ames","ates","arent",
  34.  
  35. "asse","asses","at","assions","assiez","assent",
  36.  
  37. "ant","ante","ants","antes",
  38.  
  39. "e","e","e","e"};
  40.  
  41. const char *deux_conjugaison[]={"s","s"," ","ons","ez","ent",
  42.  
  43. "e","es","e","ions","iez","ent",
  44.  
  45. "rai","ras","ra","rons","rez","ront",
  46.  
  47. "rais","rais","rait","rions","riez","raient",
  48.  
  49. "ais","ais","ait","ions","iez","aient",
  50.  
  51. "is","is","it","imes","ites","irent",
  52.  
  53. "isse","isses","it","issions","issiez","issent",
  54.  
  55. "ant","ant","ant","ant",
  56.  
  57. "u","u","u","u"};
  58.  
  59. const char *trois_conjugaison[]={"is","is","it","issons","issez","issent",
  60.  
  61. "isse","isses","isse","issions","issiez","issent",
  62.  
  63. "irai","iras","ira","irons","irez","iront",
  64.  
  65. "irais","irais","irait","irions","iriez","iraient",
  66.  
  67. "issais","issais","issait","issions","issiez","issaient",
  68.  
  69. "is","is","it","imes","ites","irent",
  70.  
  71. "isse","isses","it","issions","issiez","issent",
  72.  
  73. "issant","issant","issant","issant",
  74.  
  75. "i","i","i","i"};
  76.  
  77.  
  78.  
  79. char * pronoms[6]={"je","tu","il/elle","nous","vous","ils/elles"};
  80.  
  81.  
  82.  
  83. int viregulier(char *input)
  84.  
  85. {
  86.  
  87. FILE *fptr;
  88.  
  89. int i=0;
  90.  
  91. char buffer;
  92.  
  93. char *extension=".txt";
  94.  
  95. char nomfichier[100];
  96.  
  97.  
  98.  
  99. for(i=0;i<sizeof(irregulier)/sizeof(char*);i++)
  100.  
  101. {
  102.  
  103. if(strcmp(input,*(irregulier+i))==0)
  104.  
  105. {
  106.  
  107. strcpy(nomfichier,input);
  108.  
  109. strcat(nomfichier,extension);
  110.  
  111. printf("%s",nomfichier);
  112.  
  113. if((fptr = fopen(nomfichier, "rt")) == NULL)
  114.  
  115. {
  116.  
  117. printf("Désolé nous n'avons pas ce verbe");
  118.  
  119. return 1;
  120.  
  121. }
  122.  
  123. while((buffer = fgetc(fptr))!=EOF)
  124.  
  125. putchar(buffer);
  126.  
  127. fclose(fptr);
  128.  
  129. return 1;
  130.  
  131. }
  132.  
  133. }
  134.  
  135. return 0;
  136.  
  137. };
  138.  
  139.  
  140.  
  141. main()
  142.  
  143. {
  144.  
  145.  
  146.  
  147. char *er = "er";
  148.  
  149. char *re = "re";
  150.  
  151. char *ir = "ir";
  152.  
  153.  
  154.  
  155. char input[200];
  156.  
  157. char output[200];
  158.  
  159. const char **ptrconjugaison;
  160.  
  161.  
  162.  
  163. char *ptr;
  164.  
  165. char again = 0;
  166.  
  167. int i=0,j=0;
  168.  
  169.  
  170.  
  171. while(again!='n' && again!='N')
  172.  
  173. {
  174.  
  175. printf("\nChoisissez un verbe a conjuguer : ");
  176.  
  177. scanf("%s",input);
  178.  
  179. if(!viregulier(input))
  180.  
  181. {
  182.  
  183. ptr = &input[strlen(input)-2];
  184.  
  185.  
  186.  
  187. if(strcmp(ptr,er)==0)
  188.  
  189. ptrconjugaison = prem_conjugaison;
  190.  
  191. else if(strcmp(ptr,re)==0)
  192.  
  193. ptrconjugaison = deux_conjugaison;
  194.  
  195. else if(strcmp(ptr,ir)==0)
  196.  
  197. ptrconjugaison = trois_conjugaison;
  198.  
  199.  
  200.  
  201. printf("\nInfinitif %s\n\n",ptr);
  202.  
  203.  
  204.  
  205. input[strlen(input)-2]='\0';
  206.  
  207. strcpy(output,input);
  208.  
  209. printf("\nPresent :\n");
  210.  
  211. for(j=0;j<6;j++)
  212.  
  213. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  214.  
  215. printf("\nSubjonctif :\n");
  216.  
  217. for(j=0;j<6;j++)
  218.  
  219. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  220.  
  221. printf("\nFutur :\n");
  222.  
  223. for(j=0;j<6;j++)
  224.  
  225. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  226.  
  227. printf("\nConditionel :\n");
  228.  
  229. for(j=0;j<6;j++)
  230.  
  231. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  232.  
  233. printf("\nImparfait :\n");
  234.  
  235. for(j=0;j<6;j++)
  236.  
  237. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  238.  
  239. printf("\nPasse :\n");
  240.  
  241. for(j=0;j<6;j++)
  242.  
  243. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  244.  
  245. printf("\nImparfait du Subjonctif :\n");
  246.  
  247. for(j=0;j<6;j++)
  248.  
  249. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  250.  
  251. printf("\nParticipe Present :\n");
  252.  
  253. for(j=0;j<4;j++)
  254.  
  255. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  256.  
  257. printf("\nParticipe Passe :\n");
  258.  
  259. for(j=0;j<4;j++)
  260.  
  261. printf("%10s %s%s\n",pronoms[j],input,*(ptrconjugaison++));
  262.  
  263. }
  264.  
  265. // =======================================
  266.  
  267.  
  268.  
  269. }
  270.  
  271. printf("\nAu revoir!!\n\n");
  272.  
  273. }
Lassé par la pub ? Créez un compte