gsh: (Default)
[personal profile] gsh
If I have a file with a bunch of values seperated by '|', what is the best way
for reading them if I'm using C? The lines look like a|b|c|d|e
where a,b,c,d can be floats, integers, or even strings. It seems like there should
be an easy way to read this without having to %*c past the | characters, but I'm stumped.

Date: 2006-01-25 07:35 pm (UTC)
From: [identity profile] nminusone.livejournal.com
in sscanf etc there is a syntax roughly like %[~|]s , which will read a string up to the next | character. You can actually tell it to read strings and give it a set of 'acceptable' characters, and "~|" of course says anything but | is acceptable.

I believe this is ANSI, but not sure.

Not sure what will happen with end of lines. I usually read a whole line via other means then sscanf it apart, if needed.

Date: 2006-01-25 09:46 pm (UTC)
drwex: (Default)
From: [personal profile] drwex
strtok() is your friend.

June 2015

S M T W T F S
 123456
78 910111213
14151617181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 25th, 2026 07:01 pm
Powered by Dreamwidth Studios