C++ : Erreur
Résolu
epsiloneIB
Messages postés
133
Date d'inscription
Statut
Membre
Dernière intervention
-
epsiloneIB Messages postés 133 Date d'inscription Statut Membre Dernière intervention -
epsiloneIB Messages postés 133 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Langage : C++
Code :
char line[100];
if (strcmp(line[j],"0")!=0)
{
printf(ft,"%s",line[j]);
}
Erreur : c++ invalid conversion from 'char' to 'const char*'
Je compte sur votre aide.
Epslione
Langage : C++
Code :
char line[100];
if (strcmp(line[j],"0")!=0)
{
printf(ft,"%s",line[j]);
}
Erreur : c++ invalid conversion from 'char' to 'const char*'
Je compte sur votre aide.
Epslione
7 réponses
L'argument %s représente une chaine de caractères, or tu essaye d'afficher un seul caractère.
Essaye avec %c à la place de %s
Essaye avec %c à la place de %s
Je redonne le code :
Langage : C++
Code :
int j;
char line[100];
for (j=0;j<100;j++)
{
if (strcmp(line[j],"0")!=0)
{
printf("%s",line[j]);
}
}
Erreur : c++ invalid conversion from 'char' to 'const char*'
Merci!
Epsilone
Langage : C++
Code :
int j;
char line[100];
for (j=0;j<100;j++)
{
if (strcmp(line[j],"0")!=0)
{
printf("%s",line[j]);
}
}
Erreur : c++ invalid conversion from 'char' to 'const char*'
Merci!
Epsilone
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
pfff....
revoi tes cours sur pointeurs tableau et types.
line est un tableau de char, c'est en gros équivalent à un char*. Donc line[j] est de type char. Le prototype de strcmp est int strcmp(const char*, const char *) et toi tu lui donne un char comme premier argument.
Si tu cherche à comparer des caractère,fait le directement :
if (line[j]!='0')
pareil pour le printf -> voir message <2>
revoi tes cours sur pointeurs tableau et types.
line est un tableau de char, c'est en gros équivalent à un char*. Donc line[j] est de type char. Le prototype de strcmp est int strcmp(const char*, const char *) et toi tu lui donne un char comme premier argument.
Si tu cherche à comparer des caractère,fait le directement :
if (line[j]!='0')
pareil pour le printf -> voir message <2>
Je récapitule :
Langage :
C++
Code :
int j;
char line[100];
for (j=0;j<100;j++)
{
if (strcmp(line[j],"0")!=0)
{
printf("%s",line[j]);
}
}
Erreur :
c++ invalid conversion from 'char' to 'const char*'
Soluce :
int j;
char line[100];
for (j=0;j<100;j++)
{
if (line[j]=='0')
{
printf("%c",line[j]);
}
}
Epsilone
Langage :
C++
Code :
int j;
char line[100];
for (j=0;j<100;j++)
{
if (strcmp(line[j],"0")!=0)
{
printf("%s",line[j]);
}
}
Erreur :
c++ invalid conversion from 'char' to 'const char*'
Soluce :
int j;
char line[100];
for (j=0;j<100;j++)
{
if (line[j]=='0')
{
printf("%c",line[j]);
}
}
Epsilone