Segfault in c code.
Posted: Thu Sep 04, 2014 11:37 pm
Its probably some glaring mistake I can't seem to spot. I have a file that looks something like:
and so on.
And I am trying to parse it in C, ending up in segmentation fault (11).
Here's the code:
P.S. Debugged with LLDB, EXC_BAD_ACCESS (line 26, the head of the while loop).
Code: Select all
abc 10
bgf 20
gfg 68
And I am trying to parse it in C, ending up in segmentation fault (11).
Here's the code:
Code: Select all
char** instruction = malloc(sizeof(char) * 3);
int instructionValue = 0;
while(fscanf(inputFile, "%s %d",instruction,&instructionValue) != EOF)
{
if(strncmp(instruction,"hlt",3) == 0)
{
printf("YEAH!\n");
}
}
fclose(inputFile);