Structure qui contient une chaine
bonjour,
j'espère que vous m'aidez à comprendre pourquoi j'ai ces warning
en fait je voulais faire une structure qui contient des chaines de caracteres
bon, j'ai lu dans des doc qu'il faut specifier la longueur de la chaine si on veux faire ce cas
mais apparement ca marche sauf pour ces warning
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include<stdio.h>
typedef struct chaine{
int i;
char *c;
}chaine;
void show(chaine ch) {
printf("i=%d\n",ch.i);
printf("c=%s\n",ch.c);
}
void f(chaine *ch)
{
char* s="hello";
ch->c=malloc(strlen(s));
strcpy(ch->c,s);
ch->i=12;
}
int main(void){
chaine p;
f(&p);
show(p);
return 1;
} |
warning: incompatible implicit declaration of built-in function ‘malloc’
warning: incompatible implicit declaration of built-in function ‘strlen’
warning: incompatible implicit declaration of built-in function ‘strcpy’