For whatever reason I am unable to decipher why the compiler is throwing the uninitialized local variable exception based on a few methods I've tried. My current code is as follows.
while (fgets(line, LINE_SIZE, fh) != NULL)
{
const char s[1] = " ";
char * token;
token = strtok(line, s);
char * tokptr;
for (int i = 0; i < MAX_NUM; i++)
{
nums[i] = *token;
}
while (token != NULL)
{
strcpy(tokptr, token);
token = strtok(NULL, s);
}
}
I'm receiving an error at the line: strcpy(tokptr, token)
for an uninitialized local variable 'tokptr' and I'm lost as to why.
I've tried pre-allocating the memory for the variable by using char * tokptr = malloc(200);
but have also not had any luck with that.