#file delimeter
17 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
;compile
#include <stdio.h>
int main()
{
int ID, score;
char name[15] = {0};
if (sscanf("12#dimwit#100", "%d#%15[^#]#%d", &ID, name, &score) == 3) {
printf("ID = %d, name = %s, score = %d\n", ID, name, score);
}
else {
perror("Not correctly formatted");
}
}
ID = 12, name = dimwit, score = 100
If the formatting string just read %15s then you'd get a greedy match. You'd read "dimwit#100" as the name.
And as a result, you would not be scanning three parameters and the whole scanf() would fail.
Instead, you need to scan the name up until the first delimiter ('#').
im sorry i don't understand
but this is my code
i tried to make the input from file
then use strtok to seperate the #, but i don't really understand how can i make it store to my struct cause it's a bit random for me from the strtok, so i use mod 3 since there's only strings from each line
then i tried to print it, it so weird
that's the outcome if i just use 1 space bar
!screenshot
They're hard to read and prevent copying and pasting.