I have the following code:
int i=0;
variable a;
a.type = CHAR;
a.name = malloc(sizeof(char)+1);
while(*l->str++ != ' ');
while(*l->str != ';' || *l->str != '='){
a.name = realloc(a.name, ((!i)?1:i)*sizeof(char)+1);
a.name[i] = *l->str;
i++;
*l->str++;
}
a.name[i] = 'int i=0;
variable a;
a.type = CHAR;
a.name = malloc(sizeof(char)+1);
while(*l->str++ != ' ');
while(*l->str != ';' || *l->str != '='){
a.name = realloc(a.name, ((!i)?1:i)*sizeof(char)+1);
a.name[i] = *l->str;
i++;
*l->str++;
}
a.name[i] = '%pre%';
printf("%s\n", a.name);
';
printf("%s\n", a.name);
But it gives segment fault
.
When I remove the *l->str != '='
or the *l->str != ';'
from the while
condition it works normally. I would like to know why you give segment fault
and if there is any way with if
to solve.