Pointer from integer without a cast

Fermé
safasahnoun Messages postés 2 Date d'inscription mardi 30 octobre 2012 Statut Membre Dernière intervention 30 octobre 2012 - 30 oct. 2012 à 13:55
 Utilisateur anonyme - 30 oct. 2012 à 15:35
Bonjour,

j'ai fait ce programme en c afin de trouver la position d'un element en une chaine :
#include <stdio.h>
#include <stdlib.h>
int position(char h,char *t,int n){
int i=0;
while (i<n)
{if (h==t[i]) return(i+1);
i++;
}
return (-1);

}
int main(int argc ,char *argv){

printf ("la position est %d",position(argv[1],argv[2],(argv[3])));
return 0 ;
}


en le compilant je trouve ce problème :
In function 'main':|
|14|warning: passing argument 2 of 'position' makes pointer from integer without a cast|
|3|note: expected 'char *' but argument is of type 'char'|
||=== Build finished: 0 errors, 1 warnings ===|
A voir également:

3 réponses

safasahnoun Messages postés 2 Date d'inscription mardi 30 octobre 2012 Statut Membre Dernière intervention 30 octobre 2012 2
30 oct. 2012 à 15:22
merci bcp
2
Utilisateur anonyme
30 oct. 2012 à 15:35
Bonjour

De plus, tu as mal défini les paramètres de ta fonction main. Il faut :
int main(int argc ,char *argv[]){
2
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 840
30 oct. 2012 à 14:48
Lorsque tu appelles la fonction :
position(argv[1],argv[2],(argv[3]))
Le compilateur cherchera à appeler : position(const char*, const char*, const char*). D'où le warning.

Comment souhaites-tu lancer ton programme : nomProgramme o toto 2 ?
Si c'est le cas, il faudra :
- appeler argv[2][0] pour prendre tout simplement le 1er caractère (char)
- convertir char* en int avec strtol()

Cdlt,
1