In <11**********************@22g2000hsm.googlegroups. comSheldon <sh******@gmail.comwrites:
I have a file with a set of strings per line and each line ends with a
'\n' and each string separated by a whitespace.
After reading each line and using strtok() to split the string into 3
strings, the last string is saved with the '\n' character still
attached. I would like to know if strtok can be used to fix this
problem or do I have to use strlen and and if statement to solve this?
You could include '\n' in strtok's separator string and call strtok an
additional time.
Or you could remove the '\n' when you first read the line from your input,
before you even call strtok.
Generally, any program that deals with line-oriented input needs to decide
if it cares about the newline character at the end of every line. If not,
it's generally best to strip it out immediately after reading the line,
before the line is processed.
--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"