Pointer from integer without a cast

safasahnoun Messages postés 2 Statut Membre -  
 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 ===|

3 réponses

  1. safasahnoun Messages postés 2 Statut Membre 2
     
    merci bcp
    2
  2. Utilisateur anonyme
     
    Bonjour

    De plus, tu as mal défini les paramètres de ta fonction main. Il faut :
    int main(int argc ,char *argv[]){
    2
  3. fiddy Messages postés 441 Date d'inscription   Statut Contributeur Dernière intervention   1 847
     
    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