Question #552

How can I identify command line parameters my program was started with?

Expert's answer

To do this, you should check the variables argc and argv which contain respectively the number and the values of the parameters: int main(int argc, char* argv[]){}. Argument with index 0 is the name of the running program. The following values are the parameters of the program starting. For example:

./programm safe quick
argc = 3
argv[0] = /home/user/programm
argv[1] = safe
argv[2] = quick

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS