Problème copie tableau
ndac++
Messages postés
33
Date d'inscription
Statut
Membre
-
mype Messages postés 2459 Date d'inscription Statut Membre Dernière intervention -
mype Messages postés 2459 Date d'inscription Statut Membre Dernière intervention -
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]);
}
}
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]);
}
}
Configuration: Windows Vista Internet Explorer 7.0
2 réponses
-
-
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]); } }