Problème copie tableau

ndac++ Messages postés 35 Statut Membre -  
mype Messages postés 2449 Statut Membre -
Bonjour,
j'ai un probléme quand je l'éxucute windoxs me dit que le programme a cessé de fonctionner
voila le code
Code : C
#include <stdio.h>
#include <stdlib.h>
long copie(long tableauoriginal[], long tableaucopie[], long tailletableau);
int main(int argc, char *argv[])
{

long taille;
long a;
long tableauo[taille];
long tableauc[]={0};
long o;
printf("entrez la taille du tableau");
scanf("%ld",&taille);
printf("entrez les termes du tableau");

for(a=0;a<taille;a++)
{
scanf("%ld",tableauo[taille]);
}

o = copie(tableauo,tableauc,taille);

system("PAUSE");
return 0;
}
long copie(long tableauoriginal[], long tableaucopie[], long tailletableau)
{
long i;
for (i=0;i<tailletableau;i++)
{
tableaucopie[i]=tableauoriginal[i];
printf("%ld\n",tableaucopie[i]);
}
}
A voir également:

2 réponses

pyschopathe Messages postés 2053 Statut Membre 135
 
À quel moment ça plante ?
0
mamamiya_ Messages postés 102 Statut Membre 11
 
Bonne question :)
0
mype Messages postés 2449 Statut Membre 437
 
tu n'alloue jamais de memoire a tableauc il te faut faire de l'allocatioon dynamique avec des malloc
#include <stdio.h>
#include <stdlib.h>
long copie(long tableauoriginal[], long tableaucopie[], long tailletableau);
int main(int argc, char *argv[])
{
long taille;
long a;
long *tableauo;
long *tableauc;
long o;

printf("entrez la taille du tableau");
scanf("%ld",&taille);
printf("entrez les termes du tableau");
tableauo = (long *) malloc(sizeof(long)*taille);
for(a=0;a<taille;a++)
{
scanf("%ld",&tableauo[a]);
}
tableauc = (long *) malloc(sizeof(long)*taille);
o = copie(tableauo,tableauc,taille);

system("PAUSE");
return 0;
}
long copie(long tableauoriginal[], long tableaucopie[], long tailletableau)
{
long i;
for (i=0;i<tailletableau;i++)
{
tableaucopie[i]=tableauoriginal[i];
printf("%ld\n",tableaucopie[i]);
}
}
0