Fonction qui renvoie un tableau dynamique
Bonjour,
J'ai réalisé une petite fonction qui permet de remplir un tableau avec des chiffres
le tout fonctionne sans problème, mais j'ai messages d'alerte que je n'arrive pas à enlever lorsque je compile mon programme avec gcc
Code:
1 2 3 4
| test.c: In function main:
test.c:22:17: attention : assignment makes pointer from integer without a cast [enabled by default]
test.c: In function Function:
test.c:50:3: attention : return makes integer from pointer without a cast [enabled by default] |
et mon programme test.c
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include <stdio.h>
#include <stdlib.h>
#include <errno.h>
/* Prototype */
int Function(int taille, int *tableau);
/* Main */
int main()
{
int *tableau_final;
int nombre_case = 20;
int i;
/* Allocation */
if( (tableau_final = calloc (nombre_case,sizeof(int))) == NULL)
{
perror("Echec");
exit(0);
}
tableau_final = Function(nombre_case,tableau_final); // fonction
for(i=0;i<nombre_case;i++)
{
printf("%d\n",tableau_final[i]);
}
}
/* Function */
int Function(int la_taille, int *tab_a_envoyer)
{
int i;
/* Allocation */
if( (tab_a_envoyer = (int*) calloc (la_taille,sizeof(int))) == NULL)
{
perror("Echec");
exit(0);
}
tab_a_envoyer[0] = 0;
for(i=1;i<la_taille;i++)
{
tab_a_envoyer[i]=tab_a_envoyer[i-1]+1;
}
return(tab_a_envoyer);
} |
Mon programme ne marche plus lorsque j'essaie de suivre ces messages.