I'm making a program that reads multiple structs in and out of different files. For one of them, I have a format for reading from the file, and one for writing to it.
#include <stdio.h>
int main() {
const char* MATERIA_FORMAT_IN = "(DPAAIN.%03d;%[^;];%.2f;%.2f;%[^)])";
int id = 0;
char nome[50] = { '\0' }, status = { '\0' };
float nota1 = 0.0, nota2 = 0.0;
sscanf("(DPAAIN.001;Algoritmos e Técnicas de Programação I;10.00;10.00;CONCLUÍDA)", MATERIA_FORMAT_IN, &id, nome, ¬a1, ¬a2, status);
return 0;
}
This reads successfully into id and nome, but all other variables don't get the values I want them to get. In a scenario where this works, I want id, nome, nota1, nota2 and status to have the values of 1, "Algoritmos e Técnicas de Programação I", 10.00, 10.00 and "CONCLUÍDA", respectively.
I don't know what to try. (I think) the specifiers are right, the amount of arguments for each specifier is right, I don't know what's messing up my fscanf() (in the example above, sscanf(), and why only for this struct, seen as I did three different ones before this, including the one I wrote the logic for the first time for, and they all worked with %[^;]. I don't know what the problem is. I know the problem is in the formatter, but I don't know what else to try.
I've tried rewriting that specifier, thought maybe I had a weird character in there. Didn't work. Something is making this specifier mess up all the ones after it.
')'? Code'ssscanf()call lacks detecting if it exists.