I have this C program that gets the input from the user and sends it to a method:
#include <stdio.h>
#include <string.h>
#include "constants.h"
#include "lines.h"
#include "compare.h"
//gets arguments and sends to compare.c
int main() {
int op = 1;
char filename[20];
scanf("%d ", &op);
gets(filename);
if ((char) op + '0' < 49 || (char) op + '0' > 57) {
printf("Error: Invalid input");
exit(0);
}
readstdin(filename, op);
return 0;
}
but instead of executing the program and reading from stdin, I want it to read from the unix terminal so that:
./sort [field] < input_file
will read into the file. ([field] is option if no input is put in, default is 1).
For example the command to execute the C program in UNIX would look like this:
./sort 1 < test.txt
How do I go about doing this?
Any help is much appreicated Thanks!