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

Goldberg

Nouveau membre
:\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'

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

[cpp]#include <stdio.h>

/* ------------------------------------------------------------------------ */




void PrintDescription(void)

/* Affiche des informations concernant le crible d'Eratosthene sur la */

/* sortie standard. */

{

printf( "------------------------------------------------------\n");

printf( "Crible d'Eratosthene\n");

printf( "------------------------------------------------------\n");

printf( "Cette methode permet d'obtenir la liste des nombres\n");

printf( "premiers inferieurs a n.\n");

printf( "------------------------------------------------------\n");

}





void tab(n)
{ int i=0,a=2;
int B[n];
printf("\n");

printf("premier tableau, ts les nombres\n");
while (a<=n) {B=a; ;printf( "%d ", B); a=a+1;i=i+1;};

}


void tri(n)
{ int b, cpt=0,a;
printf("\n");
printf("\n");
int B[n];
printf("deuxieme tableau, rien que les nombres premiers\n");



for(a=2;a<=n;a++) {B[a]=a;}
for (a=2;a<=n;a++)
{if (B[a]!=0) {for(b=a+1;b<=n;b++)
{if ((B!=0) & (B%a==0)) {B=0;}}


}
}
for (a=2;a<=n;a++) {if (B[a]>0) {cpt++;printf("%d ", B[a]);}


;}


printf("\n");
if ( cpt<=1) {printf("\n%d nombre premier au total\n", cpt);};
if ( cpt>1) {printf("\n%d nombres premiers au total\n", cpt);};


}









int main()
{int choix, n;
PrintDescription();

while (1)
{printf("\n1) Crible\n2) Quit\n");
printf("\n");
scanf("%d", &choix);
switch(choix) { case 1 : printf("\nchoix n = ?\n ");
printf("\n");
scanf("%d", &n);

if (n<2) {printf("\n");printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n");
break;};
tab(n), tri(n);break;
default : printf("\n");printf("Au revoir\n");return 0;
}
}
}[/cpp]



qq'un aurait une idée?
 

thrips

Expert
C'est tes deux fonctions void tab(n) et void tri(n)

Tu devrais les écrire comme sa : void tab(int n) et void tri(int n)

Pour l'autre erreur, je sais pas.
 

DaV-X

Grand Maître
[citation=4492,1][nom]Goldberg a écrit[/nom]:\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'

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

[cpp]#include <stdio.h>

/* ------------------------------------------------------------------------ */




void PrintDescription(void)

/* Affiche des informations concernant le crible d'Eratosthene sur la */

/* sortie standard. */

{

printf( "------------------------------------------------------\n");

printf( "Crible d'Eratosthene\n");

printf( "------------------------------------------------------\n");

printf( "Cette methode permet d'obtenir la liste des nombres\n");

printf( "premiers inferieurs a n.\n");

printf( "------------------------------------------------------\n");

}




//-------------Fonction Tab-----------------
void tab(n)
{
int i=0,a=2;
int B[n];
printf("\n");

printf("premier tableau, ts les nombres\n");
while (a<=n)
{
B=a;
printf( "%d ", B);
a=a+1;
i=i+1;
}

}

//------------------Fonction tri----------------
void tri(n)
{
int b, cpt=0,a;
printf("\n");
printf("\n");
int B[n];
printf("deuxieme tableau, rien que les nombres premiers\n");

for(a=2;a<=n;a++)
{
B[a]=a;
}

for (a=2;a<=n;a++)
{
if (B[a]!=0)
{
for(b=a+1;b<=n;b++)
{
if ((B!=0) & (B%a==0))
{
B=0;
}
}
}
}

for (a=2;a<=n;a++)
{
if (B[a]>0)
{
cpt++;
printf("%d ", B[a]);
}
}

printf("\n");
if (cpt<=1)
{
printf("\n%d nombre premier au total\n", cpt);
}
if (cpt>1)
{
printf("\n%d nombres premiers au total\n", cpt);
}

}

//---------------------Main------------------
int main()
{
int choix, n;
PrintDescription();

while (1)
{
printf("\n1) Crible\n2) Quit\n");
printf("\n");
scanf("%d", &choix);

switch(choix)
{
case 1 : printf("\nchoix n = ?\n ");
printf("\n");
scanf("%d", &n);
if (n<2)
{
printf("\n");
printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n");
}
break;

tab(n), tri(n);break;

default : printf("\n");
printf("Au revoir\n");
return 0;
}
}
}[/cpp]



qq'un aurait une idée?
[/citation]

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 ]
 

DaV-X

Grand Maître
[cpp]

switch(choix)
{
case 1 : printf("\nchoix n = ?\n ");
printf("\n");
scanf("%d", &n);
if (n<2)
{
printf("\n");
printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n");
}
break;

tab(n), tri(n);break; /* Je capte pas cette ligne la...
Ya un break qui se balade sans case o_O */

default : printf("\n");
printf("Au revoir\n");
return 0;
}
[/cpp]
 

nicoprog

Grand Maître
vu le code du switch, si sa marche comme sa, il vaut mieu le remplacer par :
[cpp]
if(choix == 1)
{
printf("\nchoix n = ?\n ");
printf("\n");
scanf("%d", &n);
if (n<2)
{
printf("\n");
printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n");
}
} else {
printf("\n");
printf("Au revoir\n");
return 0;
}
[/cpp]
 

Goldberg

Nouveau membre
c mieux comme ça?

[cpp]
/**
* Solution for the exercise number 3 : The Eratosthene Crible.
* This code is ISO-C99 compliant.
**/



#include <stdio.h>



void PrintDescription(void)

/**
* Affiche des informations concernant le crible d'Eratosthene sur la
* sortie standard.
**/

{

printf("\n");

printf( "******************************************************\n");

printf( "* Eratosthene crible : *\n");

printf( "******************************************************\n");

printf( "* This method allows to obtain the list of the prime *\n");

printf( "* numbers between 0 and n. *\n");

printf( "******************************************************\n");

} // Fin de la fonction introduction



void tab(int n)

/**
* Affiche le premier tableau comprenant tous les éléments
* compris entre 2 et n compris
**/

{

int a, B[n];
printf("\n");
printf("First table, all the numbers :\n");
for (a=1;a<=n;a++) { B[a]=a; printf("%d ", B[a]); }

} // Fin de la fonction tab



void tri(int n)

/**
* Affiche le tableau des éléments premiers entre 2
* et n compris
**/

{

int b, B[n], cpt=0, a;
printf("\n");
printf("\n");
printf("Second table, only the prime numbers :\n");


// On recree un tableau comprenant tous les elements
// compris entre 2 et n

for (a=2;a<=n;a++) {B[a]=a;}


// On remet à zéro tous les elements multiples de B[a], B[a] non compris,
// et on passe au "a" suivant tant que "a" <= à "n". On supprime d'abbord
// tous les multiples de 2 (2 non compris), ensuite on passe au premier
// élement du tableau différent de 0 (=3 dans ce cas) et on supprime tous
// les multiples de 3 (3 non compris)

for (a=2;a<=n;a++)
{ for(b=a+1;b<=n;b++)
{ if ((B!=0) & (B%a==0))
{B=0;}
}

}


// On affiche à l'ecran ts les B[a] differents de zero,
// autrement dit ts les nbres premiers

for (a=2;a<=n;a++) { if (B[a]>0) {cpt++;printf("%d ", B[a]);} }


printf("\n");
if (cpt<=1) { printf("\nThere exists 1 prime number."); };
if (cpt>1) { printf("\nThere exists %d prime numbers between 1 and %d.\n",
cpt,n);
};

} // Fin de la fonction tri



int main()
{

int choix, n;
PrintDescription(); // Imprime la description à l'écran
while (1)
{printf("\nEnter 1 if you want to perform the crible.\nEnter 2 if you want to exit.\n");
printf("\nYour choice = ? "); // Ns proposons deux choix 1) crible 2) sortir du programme
scanf("%d", &choix);
switch(choix) { case 1 : printf("\n");
printf("Selected number = ? ");
scanf("%d", &n);
if (n<2) {printf("\n"); // En effet les nombres plus petits que 2 ne sont pas premiers
printf("What is the interest to perform this program with numbers<=2?\n");
break;};
tab(n), tri(n);break; // Impressions à l'écran des deux fonctions
default : printf("\n");printf("Good bye, have a nice day.\n");return 0;
}
}
} // Fin de la fonction main

[/cpp]
 

Goldberg

Nouveau membre
oups mauvaise version
[cpp]
/**
* Solution for the exercise number 3 : The Eratosthene Crible.
* This code is ISO-C99 compliant.
**/



#include <stdio.h>



void PrintDescription(void)

/**
* Affiche des informations concernant le crible d'Eratosthene sur la
* sortie standard.
**/

{

printf("\n");

printf( "******************************************************\n");

printf( "* Eratosthene crible : *\n");

printf( "******************************************************\n");

printf( "* This method allows to obtain the list of the prime *\n");

printf( "* numbers between 0 and n. *\n");

printf( "******************************************************\n");

} // Fin de la fonction introduction



void tab(int n)

/**
* Affiche le premier tableau comprenant tous les éléments
* compris entre 2 et n compris
**/

{

int a, B[n];
printf("\n");
printf("First table, all the numbers :\n");
for (a=1;a<=n;a++) { B[a]=a; printf("%d ", B[a]); }

} // Fin de la fonction tab



void tri(int n)

/**
* Affiche le tableau des éléments premiers entre 2
* et n compris
**/

{

int b, B[n], cpt=0, a;
printf("\n");
printf("\n");
printf("Second table, only the prime numbers :\n");


// On recree un tableau comprenant tous les elements
// compris entre 2 et n

for (a=2;a<=n;a++) {B[a]=a;}


// On remet à zéro tous les elements multiples de B[a], B[a] non compris,
// et on passe au "a" suivant tant que "a" <= à "n". On supprime d'abbord
// tous les multiples de 2 (2 non compris), ensuite on passe au premier
// élement du tableau différent de 0 (=3 dans ce cas) et on supprime tous
// les multiples de 3 (3 non compris)

for (a=2;a<=n;a++)
{ for(b=a+1;b<=n;b++)
{ if ((B!=0) & (B%a==0))
{B=0;}
}

}


// On affiche à l'ecran ts les B[a] differents de zero,
// autrement dit ts les nbres premiers

for (a=2;a<=n;a++) { if (B[a]>0) {cpt++;printf("%d ", B[a]);} }


printf("\n");
if (cpt<=1) { printf("\nThere exists 1 prime number."); };
if (cpt>1) { printf("\nThere exists %d prime numbers between 1 and %d.\n",
cpt,n);
};

} // Fin de la fonction tri



int main()
{

int choix, n;
PrintDescription(); // Imprime la description à l'écran
while (1)
{printf("\nEnter 1 if you want to perform the crible.\nEnter 2 if you want to exit.\n");
printf("\nYour choice = ? "); // Ns proposons deux choix 1) crible 2) sortir du programme
scanf("%d", &choix);
switch(choix) { case 1 : printf("\n");
printf("Selected number = ? ");
scanf("%d", &n);
if (n<2) {printf("\n"); // En effet les nombres plus petits que 2 ne sont pas premiers
printf("What is the interest to perform this program with numbers<=2?\n");
break;};
tab(n), tri(n);break; // Impressions à l'écran des deux fonctions
default : printf("\n");printf("Good bye, have a nice day.\n");return 0;
}
}
} // Fin de la fonction main
[/cpp]
 

DaV-X

Grand Maître
Une boucle comme ca c super illisible:

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

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

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.
 
Vous devez vous inscrire ou vous connecter pour répondre ici.
Derniers messages publiés
Statistiques globales
Discussions
730 128
Messages
6 717 841
Membres
1 586 372
Dernier membre
Meeithot
Partager cette page
Haut