I'm trying to check the command line arguments for a -i input_filename flag. If it's present I want to read the input stream from the file named there. If it's not I want to read the input from standard input.
Also, I want to check the command line arguments for a -o output_filename, if it's present it'll write the output stream named there, if not it'll write the input to standard output.
My question is whats the best way to go about doing these checks for my program? Thanks, let me know.
So far this is what I have:
FILE *fp;
if (!strcmp(argv[1], "-i") && !strcmp(argv[3], "-o")) { // Ex: -i input.txt -o output.txt
/* Input File */ fp = fopen(argv[2],"r");
// Output File output = fopen(argv4], "w");
}