On Mon, 7 Jan 2008 18:54:54 -0800 (PST), vijay <vi******@gmail.com>
wrote in comp.lang.c:
I have a file with lines like
1|22|333
4444|55555|666666
ccc|bb|a
I only need the last field. What I am doing now is using strtok to
split the lines and ignoring the first two fields. Can someone suggest
a better way to do this?
Can you define what you mean by "better"? What's wrong with using
strtok(), assuming you use it correctly?
If it were me, I'd use strchr() four times, the last three starting at
the address returned by the previous call + 1. I would verify that
the first three all returned non-null pointers, and that the last one
returned a null pointer. That way I could recognize and reject
invalid input, and still have the string I read intact to output in an
error message.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html