0

I have a code, and the error keeps saying usage: ./a.out <integer value>. I looked online for two days to see how to fix it, but I could not find any concrete answers. If someone could tell me what it means, and how I can fix it, that would be wonderful.

enter image description here

crashmstr
  • 28,043
  • 9
  • 61
  • 79
Ogey
  • 11

1 Answers1

2

It means that when you run your program you will have run it in the command line with an argument:

./ program_name(a.out) integer_value
       ^^^^^^^^           ^^^^^^
        program          argument

Where program_name is the name you gave your program when you compiled it, if you do not provide one it's default name will be a.out for linux based systems and a.exe for Windows.

integer_value is an argument you must use, otherwise the condition if(argc != 2) will evaluate to true and the program will exit showing you that message, which is part of the program.

argc is part of the main function's arguments and it represents number of arguments, including the program name, you use when executing the program.

argv is also part of the main function's arguments and is an array of strings in which argv[0] is the program name, argv[1] is the actual argument (if you have more arguments it continues, argv[2], etc.).

To answer your question, the program is fine, it doesn't need fixing, it just needs to be correctly executed. Open a command window/terminal, navigate to the directory where the executable is located an execute it as explained.

BTW, the code should be posted as text, not images.

You can learn more about command line arguments in What does int argc, char *argv[] mean?

anastaciu
  • 23,467
  • 7
  • 28
  • 53