So lets say I have a line of text in a txt file (e.g. 1234567890 DD.M.YYYY. hh:mm NAMEOFHALL) and i have around 2000 of said lines. I would like to use fscanf to pull out "1234567890", ""DD.M.YYYY", "HH:MM" and "NAMEOFHALL" as separate strings (note: NAMEOFHALL does not have a fixed length, it can vary from something short as A203 to FSB HALL B).
Here's the bit of code I'm using for scanning and seeing how the 4 separate strings look like:
while(i<lines){
fscanf(fp,"%11[^ ] %10[^ ] %5[^ ] %[^
]", polaznik[i].jmbag, polaznik[i].datum, polaznik[i].vrijeme, polaznik[i].dvorana);
printf("%s#%s#%s#%s
",polaznik[i].jmbag, polaznik[i].datum, polaznik[i].vrijeme, polaznik[i].dvorana);
i++;
}
where fp is a pointer to the .txt file
You can see the full code here.
I used hashtags in printf because I thought that there were some stray space characters in the read but there are not any.
I am expecting an output from the printf like:
0246694342#25.1.2014.#12:16#FSB Dvorana C
But instead I get:
0246694342FSB Dvorana C#25.1.2014.#12:16#FSB Dvorana C
Also please refrain from subtly roasting me as I am doing this on low energy and I'm more prone to miss obvious mistakes that way.
Thanks to anyone that replies.
question from:
https://stackoverflow.com/questions/65838360/problem-with-using-delimiters-in-c-with-fscanf 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…