why gcc emits segmentation ,after my code run
- by gcc
every time ,why have I encountered with segmentation fault ?
still,I have not found my fault
sometimes, gcc emits segmentation fault ,sometimes, memory satck limit is exceeded
I think you will understand (easily) what is for that code
void my_main()
{ char *tutar[50],tempc;
int i=0,temp,g=0,a=0,j=0,d=1,current=0,command=0,command2=0;
do{
tutar[i]=malloc(sizeof(int));
scanf("%s",tutar[i]);
temp=*tutar[i];
}
while(temp=='x');
i=0;
num_arrays=atoi(tutar[i]);
i=1;
tempc=*tutar[i];
if(tempc!='x' && tempc!='d' && tempc!='a' && tempc!='j')
{
current=1;
arrays[current]=malloc(sizeof(int));
l_arrays[current]=calloc(1,sizeof(int));
c_arrays[current]=calloc(1,sizeof(int));}
i=1; current=1;
while(1)
{ tempc=*tutar[i];
if(tempc=='x')
break;
if(tempc=='n')
{
++current;
arrays[current]=malloc(sizeof(int));
l_arrays[current]=calloc(1,sizeof(int));
c_arrays[current]=calloc(1,sizeof(int));
++i;
continue;
}
if(tempc=='d')
{
++i;
command=atoi(tutar[i])-1;
free(arrays[command]);
free(l_arrays[command]); free(c_arrays[command]);
++i;
continue;
}
if(tempc=='j')
{
++i;
current=atoi(tutar[i])-1;
if(arrays[current]==NULL)
{
arrays[current]=malloc(sizeof(int));
l_arrays[current]=calloc(1,sizeof(int));
c_arrays[current]=calloc(1,sizeof(int));
++i;
}
else
{
a=l_arrays[current]; j=l_arrays[current];
++i;}
continue;
}
}
}