I'm having trouble with file redirection into my program. I have a Makefile called test and I want to redirect a text file into it as input. For example, I want to do:
test < file.txt
as input into my executable. However, I keep getting segmentation faults when I try to read the contents of file.txt. Here is my attempt:
int main(int argc, char* argv[])
{
FILE *a;
int count;
a = fopen(argv[1], "r");
for(n = 0; ; n++)
{
count = fgetc(a); // <- here is where my program segfaults
if(feof(a))
break;
}
return 0;
}
Might anyone know why this occurs?
eofcorrectly!