468,315 Members | 1,428 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

Reading line by line in a large text file

xyz
Hi,
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..

ie., when i read for the first time , my program shuld read only one
line
and when i read for the next time , my program shuld read only second
line discarding first line..

i did it with ignore function but it is taking lot of time to reach
end of file...

please give me a simple approch to do this..

thanks to all
Jun 27 '08 #1
3 4411
xyz wrote:
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..

ie., when i read for the first time , my program shuld read only one
line and when i read for the next time , my program shuld read only
second line discarding first line..
I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?

In the first case, I don't see the problem, because you just read one
line after another.

In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.

For info on ftell & fseek, check the c++ reference:
http://www.cplusplus.com/reference/c...dio/ftell.html
Best Regards,

Lars
Jun 27 '08 #2
xyz
On Jun 9, 2:09*pm, Lars Uffmann <a...@nurfuerspam.dewrote:
xyz wrote:
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..
ie., when i read for the first time , my program shuld read only one
line and when i read for the next time , my program shuld read only
second line discarding first line..

I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?

In the first case, I don't see the problem, because you just read one
line after another.

In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.

For info on ftell & fseek, check the c++ reference:http://www.cplusplus.com/reference/c...dio/ftell.html

Best Regards,

* *Lars
What i mean is....i want the second case...
i tried storing the file positon after reading the line...
but i couldnt succeed...
could you please get some more details
Jun 27 '08 #3
xyz
On Jun 9, 2:17*pm, xyz <lavanyaredd...@gmail.comwrote:
On Jun 9, 2:09*pm, Lars Uffmann <a...@nurfuerspam.dewrote:
xyz wrote:
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..
ie., when i read for the first time , my program shuld read only one
line and when i read for the next time , my program shuld read only
second line discarding first line..
I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?
In the first case, I don't see the problem, because you just read one
line after another.
In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.
For info on ftell & fseek, check the c++ reference:http://www.cplusplus.com/reference/c...dio/ftell.html
Best Regards,
* *Lars

What i mean is....i want the second case...
i tried storing the file positon after reading the line...
but i couldnt succeed...
could you please get some more details
i got it...thanks
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Rune Johansen | last post: by
9 posts views Thread by haibhoang | last post: by
6 posts views Thread by jcrouse | last post: by
6 posts views Thread by Adrian Lin | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.