I'm attempting to do basic file reading in C with fgets. It should read one line, pass it to the tokeniser function which should split it at every ' ' and add it to a linked list. At the moment it is entering into a never ending while loop and I'm not sure why. Any help is appreciated. I am really struggling with this C language
#define INPUTSIZE 11
void tokeniseString(LinkedList *list, char *str)
{
char *token = strtok(str, " ");
while (token != NULL)
{
insertLast(list, *token);
}
}
void readInputFile(char *fileName, LinkedList *list)
{
FILE* inputFile = fopen(fileName, "r");
char str[INPUTSIZE];
printf("1");
if (inputFile == NULL)
{
perror("Could not open file");
}
else
{
while (fgets(str, INPUTSIZE, inputFile) != NULL)
{
tokeniseString(list, str);
}
if (ferror(inputFile))
{
perror("Error while reading from file");
}
}
}