Se connecter avec
S'enregistrer | Connectez-vous

Warning ds mon prog => D'où viennent-ils?

Dernière réponse : dans Programmation

:\C\bin>gcc --std=c99 -Wall -W --pedantic maite.c
maite.c: In function `tab':
maite.c:35: warning: type of `n' defaults to `int'
maite.c: In function `tri':
maite.c:46: warning: type of `n' defaults to `int'

----------------------------------------------------------------

  1. #include <stdio.h>
  2.  
  3. /* ------------------------------------------------------------------------ */
  4.  
  5.  
  6.  
  7.  
  8. void PrintDescription(void)
  9.  
  10. /* Affiche des informations concernant le crible d'Eratosthene sur la */
  11.  
  12. /* sortie standard. */
  13.  
  14. {
  15.  
  16. printf( "------------------------------------------------------\n");
  17.  
  18. printf( "Crible d'Eratosthene\n");
  19.  
  20. printf( "------------------------------------------------------\n");
  21.  
  22. printf( "Cette methode permet d'obtenir la liste des nombres\n");
  23.  
  24. printf( "premiers inferieurs a n.\n");
  25.  
  26. printf( "------------------------------------------------------\n");
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34. void tab(n)
  35. { int i=0,a=2;
  36. int B[n];
  37. printf("\n");
  38.  
  39. printf("premier tableau, ts les nombres\n");
  40. while (a<=n) {B[i]=a; ;printf( "%d ", B[i]); a=a+1;i=i+1;};
  41.  
  42. }
  43.  
  44.  
  45. void tri(n)
  46. { int b, cpt=0,a;
  47. printf("\n");
  48. printf("\n");
  49. int B[n];
  50. printf("deuxieme tableau, rien que les nombres premiers\n");
  51.  
  52.  
  53.  
  54. for(a=2;a<=n;a++) {B[a]=a;}
  55. for (a=2;a<=n;a++)
  56. {if (B[a]!=0) {for(b=a+1;b<=n;b++)
  57. {if ((B[b]!=0) & (B[b]%a==0)) {B[b]=0;}}
  58.  
  59.  
  60. }
  61. }
  62. for (a=2;a<=n;a++) {if (B[a]>0) {cpt++;printf("%d ", B[a]);}
  63.  
  64.  
  65. ;}
  66.  
  67.  
  68. printf("\n");
  69. if ( cpt<=1) {printf("\n%d nombre premier au total\n", cpt);};
  70. if ( cpt>1) {printf("\n%d nombres premiers au total\n", cpt);};
  71.  
  72.  
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. int main()
  84. {int choix, n;
  85. PrintDescription();
  86.  
  87. while (1)
  88. {printf("\n1) Crible\n2) Quit\n");
  89. printf("\n");
  90. scanf("%d", &choix);
  91. switch(choix) { case 1 : printf("\nchoix n = ?\n ");
  92. printf("\n");
  93. scanf("%d", &n);
  94.  
  95. if (n<2) {printf("\n");printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n");
  96. break;};
  97. tab(n), tri(n);break;
  98. default : printf("\n");printf("Au revoir\n");return 0;
  99. }
  100. }
  101. }




qq'un aurait une idée?

Autres pages sur : warning prog viennent

Lassé par la pub ? Créez un compte

Goldberg a écrit:\C\bin>gcc --std=c99 -Wall -W --pedantic maite.c
maite.c: In function `tab':
maite.c:35: warning: type of `n' defaults to `int'
maite.c: In function `tri':
maite.c:46: warning: type of `n' defaults to `int'

----------------------------------------------------------------

  1. #include <stdio.h>
  2.  
  3. /* ------------------------------------------------------------------------ */
  4.  
  5.  
  6.  
  7.  
  8. void PrintDescription(void)
  9.  
  10. /* Affiche des informations concernant le crible d'Eratosthene sur la */
  11.  
  12. /* sortie standard. */
  13.  
  14. {
  15.  
  16. printf( "------------------------------------------------------\n");
  17.  
  18. printf( "Crible d'Eratosthene\n");
  19.  
  20. printf( "------------------------------------------------------\n");
  21.  
  22. printf( "Cette methode permet d'obtenir la liste des nombres\n");
  23.  
  24. printf( "premiers inferieurs a n.\n");
  25.  
  26. printf( "------------------------------------------------------\n");
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33. //-------------Fonction Tab-----------------
  34. void tab(n)
  35. {
  36. int i=0,a=2;
  37. int B[n];
  38. printf("\n");
  39.  
  40. printf("premier tableau, ts les nombres\n");
  41. while (a<=n)
  42. {
  43. B[i]=a;
  44. printf( "%d ", B[i]);
  45. a=a+1;
  46. i=i+1;
  47. }
  48.  
  49. }
  50.  
  51. //------------------Fonction tri----------------
  52. void tri(n)
  53. {
  54. int b, cpt=0,a;
  55. printf("\n");
  56. printf("\n");
  57. int B[n];
  58. printf("deuxieme tableau, rien que les nombres premiers\n");
  59.  
  60. for(a=2;a<=n;a++)
  61. {
  62. B[a]=a;
  63. }
  64.  
  65. for (a=2;a<=n;a++)
  66. {
  67. if (B[a]!=0)
  68. {
  69. for(b=a+1;b<=n;b++)
  70. {
  71. if ((B[b]!=0) & (B[b]%a==0))
  72. {
  73. B[b]=0;
  74. }
  75. }
  76. }
  77. }
  78.  
  79. for (a=2;a<=n;a++)
  80. {
  81. if (B[a]>0)
  82. {
  83. cpt++;
  84. printf("%d ", B[a]);
  85. }
  86. }
  87.  
  88. printf("\n");
  89. if (cpt<=1)
  90. {
  91. printf("\n%d nombre premier au total\n", cpt);
  92. }
  93. if (cpt>1)
  94. {
  95. printf("\n%d nombres premiers au total\n", cpt);
  96. }
  97.  
  98. }
  99.  
  100. //---------------------Main------------------
  101. int main()
  102. {
  103. int choix, n;
  104. PrintDescription();
  105.  
  106. while (1)
  107. {
  108. printf("\n1) Crible\n2) Quit\n");
  109. printf("\n");
  110. scanf("%d", &choix);
  111.  
  112. switch(choix)
  113. {
  114. case 1 : printf("\nchoix n = ?\n ");
  115. printf("\n");
  116. scanf("%d", &n);
  117. if (n<2)
  118. {
  119. printf("\n");
  120. printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n");
  121. }
  122. break;
  123.  
  124. tab(n), tri(n);break;
  125.  
  126. default : printf("\n");
  127. printf("Au revoir\n");
  128. return 0;
  129. }
  130. }
  131. }




qq'un aurait une idée?


Jtai remis tout ca en ordre a l'avenir s'il te plait évite d'écrire tes boucles sur une ligne c illisible. :sweat: 

J'ai jarté quelques points virgules superflus et la syntaxe de ton switch a la fin est tres bizzare tu devrais y regarder [:666 ]

  1. switch(choix)
  2. {
  3. case 1 : printf("\nchoix n = ?\n ");
  4. printf("\n");
  5. scanf("%d", &n);
  6. if (n<2)
  7. {
  8. printf("\n");
  9. printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n");
  10. }
  11. break;
  12.  
  13. tab(n), tri(n);break; /* Je capte pas cette ligne la...
  14. Ya un break qui se balade sans case o_O */
  15.  
  16. default : printf("\n");
  17. printf("Au revoir\n");
  18. return 0;
  19. }

vu le code du switch, si sa marche comme sa, il vaut mieu le remplacer par :
  1. if(choix == 1)
  2. {
  3. printf("\nchoix n = ?\n ");
  4. printf("\n");
  5. scanf("%d", &n);
  6. if (n<2)
  7. {
  8. printf("\n");
  9. printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n");
  10. }
  11. } else {
  12. printf("\n");
  13. printf("Au revoir\n");
  14. return 0;
  15. }

c mieux comme ça?

  1. /**
  2. * Solution for the exercise number 3 : The Eratosthene Crible.
  3. * This code is ISO-C99 compliant.
  4. **/
  5.  
  6.  
  7.  
  8. #include <stdio.h>
  9.  
  10.  
  11.  
  12. void PrintDescription(void)
  13.  
  14. /**
  15. * Affiche des informations concernant le crible d'Eratosthene sur la
  16. * sortie standard.
  17. **/
  18.  
  19. {
  20.  
  21. printf("\n");
  22.  
  23. printf( "******************************************************\n");
  24.  
  25. printf( "* Eratosthene crible : *\n");
  26.  
  27. printf( "******************************************************\n");
  28.  
  29. printf( "* This method allows to obtain the list of the prime *\n");
  30.  
  31. printf( "* numbers between 0 and n. *\n");
  32.  
  33. printf( "******************************************************\n");
  34.  
  35. } // Fin de la fonction introduction
  36.  
  37.  
  38.  
  39. void tab(int n)
  40.  
  41. /**
  42. * Affiche le premier tableau comprenant tous les éléments
  43. * compris entre 2 et n compris
  44. **/
  45.  
  46. {
  47.  
  48. int a, B[n];
  49. printf("\n");
  50. printf("First table, all the numbers :\n");
  51. for (a=1;a<=n;a++) { B[a]=a; printf("%d ", B[a]); }
  52.  
  53. } // Fin de la fonction tab
  54.  
  55.  
  56.  
  57. void tri(int n)
  58.  
  59. /**
  60. * Affiche le tableau des éléments premiers entre 2
  61. * et n compris
  62. **/
  63.  
  64. {
  65.  
  66. int b, B[n], cpt=0, a;
  67. printf("\n");
  68. printf("\n");
  69. printf("Second table, only the prime numbers :\n");
  70.  
  71.  
  72. // On recree un tableau comprenant tous les elements
  73. // compris entre 2 et n
  74.  
  75. for (a=2;a<=n;a++) {B[a]=a;}
  76.  
  77.  
  78. // On remet à zéro tous les elements multiples de B[a], B[a] non compris,
  79. // et on passe au "a" suivant tant que "a" <= à "n". On supprime d'abbord
  80. // tous les multiples de 2 (2 non compris), ensuite on passe au premier
  81. // élement du tableau différent de 0 (=3 dans ce cas) et on supprime tous
  82. // les multiples de 3 (3 non compris)
  83.  
  84. for (a=2;a<=n;a++)
  85. { for(b=a+1;b<=n;b++)
  86. { if ((B[b]!=0) & (B[b]%a==0))
  87. {B[b]=0;}
  88. }
  89.  
  90. }
  91.  
  92.  
  93. // On affiche à l'ecran ts les B[a] differents de zero,
  94. // autrement dit ts les nbres premiers
  95.  
  96. for (a=2;a<=n;a++) { if (B[a]>0) {cpt++;printf("%d ", B[a]);} }
  97.  
  98.  
  99. printf("\n");
  100. if (cpt<=1) { printf("\nThere exists 1 prime number."); };
  101. if (cpt>1) { printf("\nThere exists %d prime numbers between 1 and %d.\n",
  102. cpt,n);
  103. };
  104.  
  105. } // Fin de la fonction tri
  106.  
  107.  
  108.  
  109. int main()
  110. {
  111.  
  112. int choix, n;
  113. PrintDescription(); // Imprime la description à l'écran
  114. while (1)
  115. {printf("\nEnter 1 if you want to perform the crible.\nEnter 2 if you want to exit.\n");
  116. printf("\nYour choice = ? "); // Ns proposons deux choix 1) crible 2) sortir du programme
  117. scanf("%d", &choix);
  118. switch(choix) { case 1 : printf("\n");
  119. printf("Selected number = ? ");
  120. scanf("%d", &n);
  121. if (n<2) {printf("\n"); // En effet les nombres plus petits que 2 ne sont pas premiers
  122. printf("What is the interest to perform this program with numbers<=2?\n");
  123. break;};
  124. tab(n), tri(n);break; // Impressions à l'écran des deux fonctions
  125. default : printf("\n");printf("Good bye, have a nice day.\n");return 0;
  126. }
  127. }
  128. } // Fin de la fonction main
Goldberg a édité ce message

oups mauvaise version
  1. /**
  2. * Solution for the exercise number 3 : The Eratosthene Crible.
  3. * This code is ISO-C99 compliant.
  4. **/
  5.  
  6.  
  7.  
  8. #include <stdio.h>
  9.  
  10.  
  11.  
  12. void PrintDescription(void)
  13.  
  14. /**
  15. * Affiche des informations concernant le crible d'Eratosthene sur la
  16. * sortie standard.
  17. **/
  18.  
  19. {
  20.  
  21. printf("\n");
  22.  
  23. printf( "******************************************************\n");
  24.  
  25. printf( "* Eratosthene crible : *\n");
  26.  
  27. printf( "******************************************************\n");
  28.  
  29. printf( "* This method allows to obtain the list of the prime *\n");
  30.  
  31. printf( "* numbers between 0 and n. *\n");
  32.  
  33. printf( "******************************************************\n");
  34.  
  35. } // Fin de la fonction introduction
  36.  
  37.  
  38.  
  39. void tab(int n)
  40.  
  41. /**
  42. * Affiche le premier tableau comprenant tous les éléments
  43. * compris entre 2 et n compris
  44. **/
  45.  
  46. {
  47.  
  48. int a, B[n];
  49. printf("\n");
  50. printf("First table, all the numbers :\n");
  51. for (a=1;a<=n;a++) { B[a]=a; printf("%d ", B[a]); }
  52.  
  53. } // Fin de la fonction tab
  54.  
  55.  
  56.  
  57. void tri(int n)
  58.  
  59. /**
  60. * Affiche le tableau des éléments premiers entre 2
  61. * et n compris
  62. **/
  63.  
  64. {
  65.  
  66. int b, B[n], cpt=0, a;
  67. printf("\n");
  68. printf("\n");
  69. printf("Second table, only the prime numbers :\n");
  70.  
  71.  
  72. // On recree un tableau comprenant tous les elements
  73. // compris entre 2 et n
  74.  
  75. for (a=2;a<=n;a++) {B[a]=a;}
  76.  
  77.  
  78. // On remet à zéro tous les elements multiples de B[a], B[a] non compris,
  79. // et on passe au "a" suivant tant que "a" <= à "n". On supprime d'abbord
  80. // tous les multiples de 2 (2 non compris), ensuite on passe au premier
  81. // élement du tableau différent de 0 (=3 dans ce cas) et on supprime tous
  82. // les multiples de 3 (3 non compris)
  83.  
  84. for (a=2;a<=n;a++)
  85. { for(b=a+1;b<=n;b++)
  86. { if ((B[b]!=0) & (B[b]%a==0))
  87. {B[b]=0;}
  88. }
  89.  
  90. }
  91.  
  92.  
  93. // On affiche à l'ecran ts les B[a] differents de zero,
  94. // autrement dit ts les nbres premiers
  95.  
  96. for (a=2;a<=n;a++) { if (B[a]>0) {cpt++;printf("%d ", B[a]);} }
  97.  
  98.  
  99. printf("\n");
  100. if (cpt<=1) { printf("\nThere exists 1 prime number."); };
  101. if (cpt>1) { printf("\nThere exists %d prime numbers between 1 and %d.\n",
  102. cpt,n);
  103. };
  104.  
  105. } // Fin de la fonction tri
  106.  
  107.  
  108.  
  109. int main()
  110. {
  111.  
  112. int choix, n;
  113. PrintDescription(); // Imprime la description à l'écran
  114. while (1)
  115. {printf("\nEnter 1 if you want to perform the crible.\nEnter 2 if you want to exit.\n");
  116. printf("\nYour choice = ? "); // Ns proposons deux choix 1) crible 2) sortir du programme
  117. scanf("%d", &choix);
  118. switch(choix) { case 1 : printf("\n");
  119. printf("Selected number = ? ");
  120. scanf("%d", &n);
  121. if (n<2) {printf("\n"); // En effet les nombres plus petits que 2 ne sont pas premiers
  122. printf("What is the interest to perform this program with numbers<=2?\n");
  123. break;};
  124. tab(n), tri(n);break; // Impressions à l'écran des deux fonctions
  125. default : printf("\n");printf("Good bye, have a nice day.\n");return 0;
  126. }
  127. }
  128. } // Fin de la fonction main
Goldberg a édité ce message

Une boucle comme ca c super illisible:

  1. for (a=1;a<=n;a++) { B[a]=a; printf("%d ", B[a]); }


Enfin pour moi en tout cas j'ai appris a lesfaire comme ca:
  1. for (a=1;a<=n;a++)
  2. {
  3. B[a]=a;
  4. printf("%d ", B[a]);
  5. }


Une instruction par ligne et les accolades sur une ligne repésentent bien le début et la fin de la boucle.
Tu trouves pas ca bcp plus lisible ?

edit: enfin en tout cas pour déceller les erreurs de synthaxe c bcp plus simple je trouve.
Tu vois direct si il manque un ; ou une accolade.
Lassé par la pub ? Créez un compte