Why do I get the Segmentation Fault error? I've documented a lot but couldn't clarify this.
char * sir=malloc(50*sizeof(char));
char * aux;
int i;
for(i=1;;i++)
{
fgets(aux, 50, stdin);
if(strcmp(aux,"END")==0)
break;
else
{
sir[i]=malloc(50 * sizeof(char));
strcpy(aux,sir[i]);
}
}
If I use static allocation, then I get an infinite loop.
aux2)fgetsinclude newline.strcmp(aux,"END\n")instead of. 3) type ofsirischar *.char ** sir=malloc(64*sizeof(char*));instead of. andstrcpy(aux,sir[i]);-->strcpy(sir[i],aux);