Every time I run this I encounter a segmentation fault?
I have not found my fault as sometimes gcc emits a segmentation fault and sometimes the memory stack limit is exceeded.
This is the code.
#include <stdio.h>
#include <stdlib.h>
#include "labheader.h"
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;
}
}
}