I'm learning C-programming and have got stuck on a problem to which I can't find any answer anywhere.
What I want to do is to write a C-program which I can run with additional arguments directly from the terminal, e.g.
cat -n input.txt - nosuchfile.txt input.txt
What I want to know is how I can write any function so I can run it as above (after compilation), so what the program does is perhaps not very important, but for the sake of completeness, cat takes a list of input-files and prints them to stdout. It has full error handling (hence the file nosuchfile.txt), and can also include line numbering (-n) and take input from the standard input (-).
For clarification, I have previously written programs where I can compile the source files, and run the program with e.g. ./cat
, and if input is required this has been acquired after this command to start running the program. Thus, the terminal has looked something like this:
gcc ...
./cat
-n input.txt - nosuchfile.txt input.txt
I want to know how to be able to run the program like this
gcc...
cat -n input.txt - nosuchfile.txt input.txt
Thank you very much!