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:
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.
Basically, it would look like:
Code:
Bob,Jerry Address Phone
Mary,Sarah Address Phone
...
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.