C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-18-2006, 04:07 PM   #1
Registered User
 
Join Date: Nov 2005
Location: Canada
Posts: 80
reading the nth item from a txt file

if the items in the txt file are separated by space, or tab, how is it possible to read the nth item?

lets say the txt is as follows:
Code:
2 3 4 5 6 7 8 9 0
1 2 11 4
55 6 1 9 0 35 4
2 2 1
and i want to only read the 3rd item on each row.

the other questions is, how would you only count the number of items on the first row of the txt file? in the above case, it should be 9 since the 1st line has 9 items.

thanks.
Opel_Corsa is offline   Reply With Quote
Old 11-18-2006, 05:58 PM   #2
Registered User
 
Join Date: Jan 2005
Posts: 7,250
Read in a line into a string, then parse the line. Since those are integers, the easiest way to parse a line would probably be to create a stringstream with the string and then use a loop to read each integer from the stringstream. Use a counter to find the third one and to identify the total number.
Daved is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie homework help fossage C Programming 3 04-30-2009 04:27 PM
Immediate programming help! Please! xMEGANx C++ Programming 6 02-20-2008 12:52 PM
gcc link external library spank C Programming 6 08-08-2007 03:44 PM
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM
Unknown Memory Leak in Init() Function CodeHacker Windows Programming 3 07-09-2004 09:54 AM


All times are GMT -6. The time now is 05:09 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22