Pointer from integer without a cast
safasahnoun
Messages postés
2
Date d'inscription
Statut
Membre
Dernière intervention
-
Utilisateur anonyme -
Utilisateur anonyme -
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 ===|
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:
- Pointer from integer without a cast
- Vlc cast to tv - Guide
- Win setup from usb - Télécharger - Utilitaires
- Installer chrome cast - Guide
- Attempting boot from usb device - Forum Windows 10
- Reinitialiser chrome cast - Guide
3 réponses
Bonjour
De plus, tu as mal défini les paramètres de ta fonction main. Il faut :
De plus, tu as mal défini les paramètres de ta fonction main. Il faut :
int main(int argc ,char *argv[]){
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,
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,