Next: Low Level I/O Up: Input and Output (I/O) Previous: sprintf and sscanf

Command line input

C lets read arguments from the command line which can then be used in our programs.

We can type arguments after the program name when we run the program.

We have seen this with the compiler for example

c89 -o prog prog.c

c89 is the program, -o prog prog.c the arguments.

In order to be able to use such arguments in our code we must define them as follows:

main(int argc, char **argv)

So our main function now has its own arguments. These are the only arguments main accepts.

A simple program example:

Assume it is compiled to run it as args.

So if we type:

args f1 ``f2'' f3 4 stop!

The output would be:
Wed Sep 14 10:06:31 BST 1994