J'utilise un procédure pour pouvoir copier un tableau dans un autre tableau, en faite quand j'utilise la même boucle pour les deux tableau cela fonctionne, mais quand je souhaite utiliser chaque boucle à part cela ne fonctionne pas, ça me copie juste la dernière valeur du premier tableau.
Quelqu'un peut m'expliquer pourquoi
Voila le code qui fonctionne :
#include<stdio.h>
#include<conio.h>
void copieTableau(int tab[],int copieTab[], int taille);
int main(int argc, char *argv[])
{
int tab[5];
int copieTab[5];
tab[0]=13;
tab[1]=14;
tab[2]=15;
tab[3]=33;
tab[4]=12;
copieTableau(tab,copieTab,5);
getch();
}
void copieTableau(int tab[],int copieTab[], int taille)
{
for(int i = 0; i<taille; i++)
for(int i=0,j=0 ; i<taille & j<taille;i++,j++)
{
copieTab[j]= tab[i];
}
printf("voila le premier tableau:");
for(int i=0;i<taille;i++)
{
printf ("%d ",tab[i]);
}
printf(" \n voila le deuxieme tableau:");
for(int j=0;j<taille;j++)
{
printf ("%d ",copieTab[j]);
}
}
Voila le code qui ne fonctionne pas :
#include<stdio.h>
#include<conio.h>
void copieTableau(int tab[],int copieTab[], int taille);
int main(int argc, char *argv[])
{
int tab[5];
int copieTab[5];
tab[0]=13;
tab[1]=14;
tab[2]=15;
tab[3]=33;
tab[4]=12;
copieTableau(tab,copieTab,5);
getch();
}
void copieTableau(int tab[],int copieTab[], int taille)
{
for(int i = 0; i<taille; i++)
for(int j=0 ;j<taille;j++)
{
{
copieTab[j]= tab[i];
}}
printf("voila le premier tableau:");
for(int i=0;i<taille;i++)
{
printf ("%d ",tab[i]);
}
printf(" \n voila le deuxieme tableau:");
for(int j=0;j<taille;j++)
{
printf ("%d ",copieTab[j]);
}
}
On écrit "j'ai tort", pas "tord" qui est le verbe "tordre" à la 3ème personne de l'indicatif présent