Why don't the Get functions, GetString, GetInt etc, take command line arguments like the main function? It seems to me that they should since command lines are being inputed into the function.

  • Why do you think they should take command line inputs? – sinister Sep 17 '14 at 16:10
  • isn't the getint taking something that has been typed into standard input, then turning it into an int to be used by the program? To me this is similar, (if not exactly similar) to how you type a command line for main. – William Kenney Sep 17 '14 at 20:19
  • Both of them are different, "Command-line arguments are passed to the program in an array and it can do what it wants with them; stdin is an input stream the program has to request data from." quoted from here. – sinister Sep 18 '14 at 0:30
  • ok thanks for your response. I see the difference between streams and command-line arguments, (and I see that you wouldn't put argv or argc in GetInt for example) but my gut instinct still says it is strange GetInt is a void function, because it is still using the text from stin as input. – William Kenney Sep 18 '14 at 10:05

main is a special function. It's the starting point of a C program — it's called somehow magically when you execute the program from the terminal by typing its name in as follows


main can be declared to receive command-line arguments. Command-line arguments are special type of arguments in a sense that they're passed to your program via the command-line (or the terminal) as you execute your program — you pass them as you start the program as follows

./programName arg1 arg2 

Unlike command-line arguments, regular arguments are passed to functions in your program as the program is being executed — as the program is running already.

This basically tells you that we can't let any function other than main to take command-line arguments. However, any function can be declared to take regular arguments as we need to.

GetString, GetInt, ... are defined to prompt the user for input as the program is running, validate it and return it. Now, the input that any of these functions takes from the user is also via the command-line. However, it's not regarded as a command-line argument as I defined command-line arguments earlier that they're passed as you execute the program.

These are different ways of inputting data to your program and there are many more ways.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .