-
Reading spaces from file
Hello
I know how to read most information from file for example if I have this in a file:
Hammer;10;9.99
Phillips Head Screwdriver;5;7.99
Saw;2;9.95
I would use:
Code:
while (3 == fscanf(fp, "%[^;];%d;%lf\n", name, &qu, &amount))
But how Can I scan a file that is divided with spaces? For example:
Seinfeld 50 75
Carson 40 20
Leno 45 50
Letterman 20 95
I tried a couple of things, but I was unsuccessful, How Can I do this?
-
I'd try something like
"%[^0-9]%d %lf"
and then trim the first string
-
First I would suggest you read the whole like using fgets, then attempt to parse it with sscanf.
If the converted result isn't 3, then the file is already tidied up for you (because you read the whole line with fgets).