Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File input

Status
Not open for further replies.

kriscs1

Programmer
Jul 5, 2005
12
GB
Hi, I have a file of words, all seperated by commas, in longs lines right to the end of the file. Some of the words go over on to the next line. How would I get all of these words individually into a variable? Any help would be great or a pointer to a website.
I hope this is not too much to ask.
Thanks very much
kris
 
Well, read a file char by char and append every char to string buffer variable (and skip whitespaces) until comma (process a word then continue)or end-of file (process a word then break) condition raised...
Don't forget to clear a buffer before next word scanning.
I hope it's so simple...
 
Again, if you're using C++, this is simple. Use getline with ',' as the delimiter and you can read in each word one at a time.

When you say some of the words go over on to the next line, I assume you mean that they wrap when you look at them in your text editor. If that's the case, then technically they are still on the same line because there is no newline separating the two lines. If there is a newline, then a little extra processing would need to be done.
 
ahh thank you.. i did not know you could use a delimeter with getline().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top