The program crashes in the while loop, which is not surprising as the pointer last has the value NULL.
Questions *last = NULL;
while (fscanf(file, "%d,%99[^,],%19[^,],%19[^,],%19[^,],%19[^,],%c,%9[^,\n]\n",
&(last->difficulty), last->question,
last->optionA, last->optionB, last->optionC, last->optionD,
&(last->answer), last->category) == 8) {
It might be better to first read a complete line with fgets and then search for the columns with strtok(). This would have the advantage of being safer and more flexible, as you would not have to work with static text lengths.
// edit1:
The csv file contains special Hungarian characters. Presumably these are difficult to read as char. I would recommend wchar_t. Depending on the operating system and compiler, there are other things to consider.
I would also like to point out that it is very easy to localize errors with a debugger.
Please also provide further information on the operating system and compiler so that a meaningful answer is possible.
Would C++ also be an option?
// edit2:
Reading the CSV could look like this (some error messages are missing):
void appendQuestion(Questions** head, Questions* newQuestion);
void readCSV(Questions** head, const char* filename);
void freeQuestions(Questions* head);
void readCSV(Questions** head, const char* filename)
{
FILE *file = fopen(filename, "r");
if (file == NULL) {
perror("Error: Failed to open the file.\n");
return;
}
wchar_t line[MAX_LINE_LENGTH];
wchar_t delim[] = L";\n"; wchar_t *token, *context=NULL;
fgetws(line, sizeof(line), file);
while (fgetws(line, MAX_LINE_LENGTH, file) != NULL)
{
Questions* last = (Questions*)malloc(sizeof(Questions));
last->next = NULL;
token = wcstok(line, delim, &context);
if (!token) break;
last->difficulty = _wtoi(token);
token = wcstok(NULL, delim, &context);
if (!token) break;
wcsncpy(last->question, token, sizeof(last->question)/sizeof(wchar_t)-1);
...
appendQuestion(head, last); }
fclose(file);
}