Well the problem I had it I was able to fix as I only need one char*, but I coming to needing it somewhere else now. Anyway I went back and changed the char* to a char* array of 50 and just used the 0 element. Here's the code:
Code:
char* lines[50];
file = fopen("settings.cfg", "r");
if (file == NULL) {
writeConfig(*settings);
return false;
}
while (fscanf(file, "%s", lines[0]) != EOF) {
if (stricmp(lines[0], "screenRes") == 0) {
fscanf(file, "%s", lines[0]);
if (stricmp(lines[0], "=") == 0)
fscanf(file, "%d %s %d", &settings->video->width, lines+0,
&settings->video->height);
else
return false;
} else if (stricmp(lines[0], "bitDepth") == 0) {
fscanf(file, "%s", lines+0);
if (stricmp(lines[0], "=") == 0)
fscanf(file, "%d", &settings->video->bits);
else
return false;
} else if (stricmp(lines[0], "zBBuffBits") == 0) {
fscanf(file, "%s", lines[0]);
if (stricmp(lines[0], "=") == 0)
fscanf(file, "%d", &settings->video->zBits);
else
return false;
} else if (stricmp(lines[0], "viewDist") == 0) {
fscanf(file, "%s", lines+0);
if (stricmp(lines[0], "=") == 0)
fscanf(file, "%f", &settings->video->viewDistance);
else
return false;
} else if (stricmp(lines[0], "fullscreen") ==0) {
fscanf(file, "%s", lines[0]);
if (stricmp(lines[0], "=") == 0)
fscanf(file, "%d", &settings->video->fullscreen);
else
return false;
}
}
When I just use a char* and use stricmp() and fscanf() on it, it's fine. But declaring that array and trying to set or access an element in the array causes it to crash.
Edit: Not sure if anyone noticed, but I had file+0 at the end, I took it out, and it still crashes, so that's not really the problem, if you caught it.