Probleme arguments en C
maxstag
-
Hxyp Messages postés 401 Date d'inscription Statut Membre Dernière intervention -
Hxyp Messages postés 401 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'ai un problème avec un strcpy et un strtok qui me renvoient des warnings sur codeblocks.
Visiblement c'est ma variable pcommande qui doit etre mal définie ou mal utilisée.
Les erreurs sont en gras vers la fin du code (ne faites pas attention aux fonctions ou variables "inutiles", ceci est un fragment de mon code)
Voici mon code:
et voici les messages d'erreurs
Merci de votre aide =)
J'ai un problème avec un strcpy et un strtok qui me renvoient des warnings sur codeblocks.
Visiblement c'est ma variable pcommande qui doit etre mal définie ou mal utilisée.
Les erreurs sont en gras vers la fin du code (ne faites pas attention aux fonctions ou variables "inutiles", ceci est un fragment de mon code)
Voici mon code:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define NB_CARACTERES 100 #define NB_LIGNES 20 #define MAX 255 #define NB_ELEVES 99 //Variables int F10=1; //Prototypes int decoupe_commande(char *commande, char *tableau_commandes[]); int main() { char commande[NB_CARACTERES]; char *tableau_commandes[NB_LIGNES]; int nb_mots=0; do { F10=saisie_chaine(commande, "Entrez une commande(toucheF10 pour quitter ou commande eponyme)"); nb_mots=decoupe_commande(commande, &tableau_commandes[NB_LIGNES]); printf("Le nombre de mots est %d\n ", nb_mots); analyse(&tableau_commandes[NB_LIGNES]); }while(F10!=0); printf("\n Good bye"); return 0; } int decoupe_commande(char *commande, char *tableau_commandes[]) { char *temporaire; char *pcommande[NB_CARACTERES]={0}; char *espace={" "}; int nb_mots=0; strcpy(pcommande, commande); temporaire = strtok(pcommande, espace); tableau_commandes[nb_mots]=temporaire; printf("Commande entree : %s\n",tableau_commandes[nb_mots]); while(temporaire !=NULL) { nb_mots++; temporaire = strtok(NULL,espace); tableau_commandes[nb_mots]=temporaire; printf("argument %d : %s\n",nb_mots, tableau_commandes[nb_mots]); } return nb_mots; }
et voici les messages d'erreurs
C:\Users\Maxstag\TP3 final\main.c||In function 'decoupe_commande':| C:\Users\Maxstag\TP3 final\main.c|81|warning: passing argument 1 of 'strcpy' from incompatible pointer type| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\string.h|45|note: expected 'char *' but argument is of type 'char **'| C:\Users\Maxstag\TP3 final\main.c|83|warning: passing argument 1 of 'strtok' from incompatible pointer type| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\string.h|57|note: expected 'char *' but argument is of type 'char **'| ||=== Build finished: 0 errors, 2 warnings ===|
Merci de votre aide =)
A voir également:
- Probleme arguments en C
- Vous avez entré un nombre insuffisant d'arguments pour cette fonction - Forum Excel
- Les arguments de tableau de countifs ne sont pas de la même taille. ✓ - Forum Excel
- Les arguments de tableau de sumifs ne sont pas de la même taille. - Forum Excel
- SOMME.SI.ENS retourne l'erreur #VALEUR! ✓ - Forum Excel
- Vous avez entré un nombre trop important d'arguments pour cette fonction ✓ - Forum Excel
1 réponse
Bonjour,
strcpy prend un tableau de char en paramètre et vous lui passez un tableau de pointeurs type char :
exemple 1 :
exemple 2 :
strcpy prend un tableau de char en paramètre et vous lui passez un tableau de pointeurs type char :
char *pcommande[NB_CARACTERES];
exemple 1 :
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { char *t[20],*s="hello world"; t[0]=malloc(sizeof(char)*100); strcpy(t[0],s); printf("%s\n",t[0]); free(t[0]); return 0; }
exemple 2 :
#include <stdio.h> #include <string.h> int main(void) { char t[100],*a="hello world"; strcpy(t,a); printf("%s\n",a); return 0; }