I ran this on two compilers. One gave me a seg fault, the other runs it fine.
Code:
void parse(char *line)
{
char temp;
int i;
int j;
int k, l;
int length = 0;
char *string = malloc(sizeof(char) * 50);
char *firstName = malloc(sizeof(char) * 50);
char *lastName = malloc(sizeof(char) * 50);
do{
if((*(line + i)>=65)&&(*(line + i)<=90))
{
k = 0;
l= 0;
j = i;
while(*(line + j) != ' '){
j++;
}
j++;
while(*(line + j) != ' '){
j++;
}
for(k = i; k < j; k++)
{
*(string + l) = *(line + k);
l++;
}
//when I'm done it will pass string to another function that will check if it is a name or not, but for now I'm just printing it.
printf("%s\n", string);
}
i++;
}while(i < 100);
}
Any ideas as to why I get a segfault with one compiler? Or ways I can improve this?