Suppose I want to read the 50th line of a text file, is there a way to do that?
Reading a certain line in a file
Started by sourlemon, Feb 28 2009 11:53 AM
6 replies to this topic
#1
Posted 28 February 2009 - 11:53 AM
|
|
|
#3
Posted 28 February 2009 - 01:52 PM
Thank you Aereshaa. But how would I make my program skip to the 49th newline?
I'm newbie with this, so I'm not sure I understand you correctly.
The only line reading I know is fgets, which reads a line. So, if I want to read the 50th line, I would have to put it in a loop and count how many time I calls fgets?
I'm newbie with this, so I'm not sure I understand you correctly.
The only line reading I know is fgets, which reads a line. So, if I want to read the 50th line, I would have to put it in a loop and count how many time I calls fgets?
#4
Posted 28 February 2009 - 02:01 PM
#5
Posted 28 February 2009 - 03:22 PM
So paying attention in class does pay off :) Thank you. But what's a buffer? And how can I create that?
Another question, suppose I looked at the 50th line. How do I restart at the first line again?
Another question, suppose I looked at the 50th line. How do I restart at the first line again?
Edited by sourlemon, 28 February 2009 - 05:05 PM.
#6
Posted 28 February 2009 - 05:34 PM
A buffer means the string that you read the line into:
char buf[100];
To restart a file, call fseek(file, 0, SEEK_SET)
if you have any problems post your code and we'll work them out.
char buf[100];
To restart a file, call fseek(file, 0, SEEK_SET)
if you have any problems post your code and we'll work them out.
#7
Posted 01 March 2009 - 01:57 PM
Ahhh that's a buffer. Got that and the fseek :) Thank you Aereshaa.


Sign In
Create Account


Back to top









