C program with command line options
c, terminal, ubuntu
Solution
`void main ()` is wrong, if you copied this from a book, throw the book away
It should be `int main(int argc, char **argv)`, argc will then be set to the number of arguments and argv[1] .... argv[argc-1] are the argument strings (argv[0] is the name of the program)
Problem
I wonder how to write a C program with options that can be invoked by a terminal. Example : Person.c ``` #include <stdio.h> void main () { char option; if(option == 'f') printf("First Name"); else if(option == 'l') printf("Last Name"); else printf("Full Name"); } ``` Compile it with cc Person.c -o Person Objective : I want to reach my program options through terminal. Example : ``` ./Person -f ``` Output : First Name