Hi all, I'm pretty new to C, so apologies in advance, I am trying to write code that will allow me to input a line no and then display the text from that line from the corresponding file. I'm having a bit of a brain fart & can't work it out, any help would be much appreciated.
#include <stdio.h>
#include <stdlib.h>
#define MAX_CHARACTERS 81
main()
{
FILE *fp_in;
char one_line[MAX_CHARACTERS];
int line_numbers=0;
if ( (fp_in=fopen("file.txt","r"))==NULL)
puts("Error in opening file.txt" );
else
{
printf("\nChoose line to display: ");
scanf("%d",&line_numbers);
}
while (fgets(one_line,MAX_CHARACTERS,fp_in )!=NULL )
{
printf("%s",one_line);
}
fclose ( fp_in );
}