so i'm pretty new to C and i've been trying to figure out how to read a text file in for reading as in the line below.
./atc < example_input_001.txt
I'm trying to print the lines out one by one but I don't know how to access the file.
So far I've just been reading in the file like this but that's only because I know the file name, I need the program to work for any file given in the command line.
FILE *open_ADSB_file = fopen("example_input_001.txt", "r");
if (open_ADSB_file == NULL) {
printf("No valid file\n");
exit(1);
}
You are close. What you are using is called
stdin. You can accessstdinjust like a file. You should replace yourfopencall with something more likefreopen(NULL, "r", stdin).freopen()reference