Mail Archives: djgpp/1999/10/25/02:25:55
I totally confused my lecturer by understanding pointers and
struggling with filestreams, don't be disparraged it's not an easy
concept. Well heres your answer.
There are many ways to do it, however no book I've ever read has given
the answer. This is the way I'd do it.
struct MyStuff
{
int Number;
};
int ReadLine(struct MyStuff *Meep, FILE *fp, int Line)
{
struct MyStuff Temp;
int i = 0, RetVal = -1;
rewind(fp); // Make sure you know where your file pointer is!!!
while( i != (Line-1) || !feof(fp)) /* Must not go past EOF */
{
fscanf(fp, "%d", &Temp.Number);
i++;
if(feof(fp))
{
RetVal = 0;
}
}
if( RetVal = -1 )
{
/* OK you are now at the line you want to read */
fscanf(fp, "%d", &Meep->Number);
}
return RetVal; /* Returns 0 if unsucsesful, otherwise -1 */
}
- Raw text -