Tokenizing files?

Joined
Sep 9, 2006
Messages
1
Reaction score
0
While playing around with the strtok() function, I realized that no equivalent existed for files, at least to my knowledge. In my current project, my program opens a file which is delimited by lines (or '\n'), with each line delimited by spaces (or ' '), followed by certain tokens needing to be further delimited by commas (or ',').

Basically, it would look like:
Code:
Bob,Jerry Address Phone
Mary,Sarah Address Phone
...
My current implementation uses getc() to pull the next character from the FILE* stream. From there, I use if conditions to determine the character and then strncat() them onto a char*. However, this solution can be cleaner, because everytime I strncat(), I also have to realloc() to avoid memory collisions.

Just as an aside, I prefer not to use fgets(), simply because that limits the buffer, which in turn may truncate part of the file.

In closing, I would like to mention that I am actually quite new to the C language. If what I'm looking for doesn't exist, please let me know. And of course, if anyone has a better implementation than what I currently have, by all means please share it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top