ok it's working now
though could someone explain to me why changing it from i = 0 to i = 1 fixed it? thanks
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main(void)
{
int i = 1, line, check;
FILE *fp;
char words[MAX+1], fname[MAX+1];
puts("Enter filename");
gets(fname);
// fgets(fname, 100, stdin);
if((fp = fopen(fname, "r")) == NULL)
{
fprintf(stdout, "Can't open %s file.\n", fname);
exit(1);
}
puts("Enter the line you wish to see");
scanf("%d", &line);
while(i < line && (check = fgetc(fp)) != EOF)
if(check == '\n')
i++;
if (check == EOF)
printf("\nEnd of file reached before given line\n");
else
{
fgets(words, 100, fp);
puts("Line contents:");
puts(words);
}
if(fclose(fp) != 0)
fprintf(stderr,"Error closing file\n");
return 0;
}