Problème copie tableau

Fermé
ndac++ Messages postés 31 Date d'inscription lundi 23 février 2009 Statut Membre Dernière intervention 19 septembre 2009 - 24 avril 2009 à 22:25
mype Messages postés 2435 Date d'inscription jeudi 1 novembre 2007 Statut Membre Dernière intervention 16 août 2010 - 25 avril 2009 à 16:26
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 1973 Date d'inscription dimanche 2 mars 2008 Statut Membre Dernière intervention 22 mars 2010 135
24 avril 2009 à 22:50
À quel moment ça plante ?
0
mamamiya_ Messages postés 99 Date d'inscription samedi 15 septembre 2007 Statut Membre Dernière intervention 24 février 2014 11
24 avril 2009 à 22:51
Bonne question :)
0
mype Messages postés 2435 Date d'inscription jeudi 1 novembre 2007 Statut Membre Dernière intervention 16 août 2010 436
25 avril 2009 à 16:26
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