Read and discard lines 1 and 2, then read line 3 and you've got it.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
I would open the file and read three lines into it and then display the results...This sounds like a for loop to me..
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
Read and discard lines 1 and 2, then read line 3 and you've got it.
As in...
#include <stdio.h>
void fetch(const char *filename, int lineno)
{
char line [ 128 ];
int i;
FILE *file = fopen ( filename, "r" );
if ( file )
{
for ( i = 0; i < lineno; ++i )
{
if ( fgets ( line, sizeof line, file ) == NULL )
{
return;
}
}
fputs ( line, stdout );
fclose ( file );
}
else
{
perror ( filename );
}
}
int main ()
{
fetch ( "a.txt", 3 );
return 0;
}
/* a.txt
1;27.01.1957;8;12;31;39;43;45;
2;03.02.1957;5;10;11;22;25;27;
3;10.02.1957;18;19;20;26;45;49;
4;17.02.1957;2;11;14;37;40;45;
5;24.02.1957;8;10;15;35;39;49;
*/
/* my output
3;10.02.1957;18;19;20;26;45;49;
*/
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314