Problème copie tableau
ndac++
Messages postés
35
Statut
Membre
-
mype Messages postés 2449 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]);
}
}
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:
- Problème copie tableau
- Tableau word - Guide
- Copie cachée - Guide
- Tableau ascii - Guide
- Trier un tableau excel - Guide
- Super copie - Télécharger - Gestion de fichiers
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]);
}
}