2/23/10

In this simple example we will see how to use the command line arguments in our C programs.Well, we all noticed that main() get two parameters.int main(int argc, char *argv[]);argc is an integer representing the size of argv[]argv is a table of pointer to chars ( Strings )Below is a simple calculator which takes as arguments two numbers and prints the sum.The code is:

Now lets explain the code:line 4 : we check if the user passed two arguments to the program. We actually need two arguments but in C the first argument ( argv[0] ) is the name of our program, so we need two more.line 5 : If the user didn't pass two arguments we print the usage of our program and exitline 8 : Using atoi() function we convert pointers to char (string) to decimal numbers and display their sum

I have been desperately looking for info about this and discovered your website via yahoo. It is undoubtedly one for my bookmarking! Keep up the good work I will pop back again soon.Time and Attendance Software