ok changed to
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main(void)
{
int i = 0, line, check;
FILE *fp;
char words[MAX+1], fname[MAX+1];
puts("Enter filename");
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);
for(i=0; i < line; i++)
{
check = fgetc(fp);
if (check != EOF)
if (check == 't')
i++;
else
break;
}
// while(i < line && (check = fgetc(fp)) != EOF)
// if(check == ' ')
// 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;
}
and still getting
Code:
[Session started at 2007-08-03 14:54:15 -0400.]
Enter filename
testrun.txt
Enter the line you wish to see
1
End of file reached before given line
Prime has exited with status 0.
though I just double checked the file, and found that when I set it to "w" for fopen it still had the other file by the same name (obviously an empty file) and removed it. Now I can't get the program to see the file, where am I supposed to put it (I'm doing this in Xcode as a project, might have to compile it on Terminal since I know where that looks)