Bonjour, je suis débutant en C, et j'ai voulu crée un programme qui fait une copie d'un tableau d'entier de taille N vers un autre, pour cela , j'ai crée 4 fonctions: fonction.h fonction.c le Makefile et main.c , dont les voici .Mais ,à chaque fois que je compile, le compilateur m'affiche :
Pour le Makefile
1 2 3 4 5 6 7 8
| exe :main.o fonction.o
gcc -o exe main.o fonction.o -Wall -lm
fonction.o:fonction.c
gcc -c fonction.c
main.o :main.c fonction.h
gcc -c main.c
clean:
rm *.o exe |
Pour la fonction :"fonction.h"
1 2 3 4 5 6
| #ifndef fonction_h
#define fonction_h
int taille(char *s);
int *initTAB(int n);
int copie(int *tab,int N);
#endif |
Pour la fonction :"fonction.c"
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| #include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
int copie(int *tab,int N)
{
int *t=(int*)malloc(N*sizeof(int)); // c'est ce talbeau qui sera en "return"!!
int k;// l'incrementation
for (k=0;k<N;k++)
{
*(t+k)=*(tab+k);
}
return(t); // t, c'est le tableau retourné
} |
Et quand je compile( sous geany, avant de de le "make" ), il m'affiche cet avertissement:
fonction.c:13:3: attention : return makes integer from pointer without a cast [enabled by default]
C'est quand je le caste en int (j'ai pas compris le pourquoi!!) que l'erreur disparait!
Idem pour la fonction main.c :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include "fonction.h"
int main()
{
int q;
int n=5;
int *tab;
//tab=initTAB(n);
int source[5]={6,5,4,3,2};
tab=copie(source,n);
for(q=0;q<n;q++) printf("tab[%d]=%3d\n",q,*(tab+q));
return 0;
} |
le compilateur me dit:
main.c:13:5: attention : assignment makes pointer from integer without a cast [enabled by default]
Partager