Bonjour a tous;
J'ai besoins d'aide sur une erreur de segmentation.
Code C/C++ :
int decoupeLignePipe(char *chaine,char **commande1,char **commande2)
{
int p,i,u,taille;
int e=0;
int j=0;
int r=0,k=0;
int pipe=0;
for(i=0;i<10;i++)
commande1[i]=(char *)malloc(50);
for(p=0;p<10;p++)
commande2[p]=(char *)malloc(50);
while(chaine[e]!=0)
{
while((chaine[e]>='a' && chaine[e]<='z')||(chaine[e]>='0' && chaine[e]<='9')||chaine[e]=='_'||chaine[e]=='.'|| chaine[e]== '-' || chaine[e]== '|')
{
if(chaine[e]=='|')
pipe=1;
if(pipe==1)
{
commande2[r][j]=chaine[e];
e++;
j++;
}
else
{
commande1[k][j]=chaine[e];
e++;
j++;
}
}
while(chaine[e]==' ')e++;
if(pipe==1)
{
r++;
j=0;
}
else
{
k++;
j=0;
}
}
/*commande1[k]=NULL;*/
commande2[r]=NULL;
taille=k+r;
return taille;
}
int main(int args,char **arg,char **envp)
{
int p;
int k;
char chaine[256];
char **commande1;
char **commande2;
int taille=0;
affichePrompt(envp);
lit(chaine);
printf("commande saisie : %s\n",chaine);
int taille=decoupeLignePipe(chaine,commande1,commande2);
for(p=0;p<taille;p++) {// pour tester cond
printf("lu : %s\n",commande1[p]);
}
}
Le probleme je ne comprend pas pourquoi ya cette erreur
:
Program received signal SIGSEGV, Segmentation fault.
0x08048749 in decoupeLignePipe (chaine=0xbffff20c "sd s|sd ",
commande1=0xbffff254, commande2=0x15cf80) at minishelltest.c:75
75 commande2[p]=(char *)malloc(50);}