What Sebastiani stated, but on a tangent you may want to review the use of getopt().

Example of Getopt - The GNU C Library