How can make it where the program reads any two integers input before the program is run? I want the output to look like this, with x and y being any variables typed in (I am using Cygwin):
$ ./a x y
product of x and y
sum of x and y
I used int main(int argc, char *argv[])
. I tried to assign argv[2]
to x
and argv[3]
to y
, but when I compile the program it says assignment makes integer from pointer without cast. What does this mean and how do I fix it?
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments. The value of argc should be non negative. argv(ARGument Vector) is array of character pointers listing all the arguments.
option. You can test command line arguments by running an executable from the "Command Prompt" in Windows or from the "DOS prompt" in older versions of Windows. You can also use command line arguments in program shortcuts, or when running an application by using Start -> Run.
A command line argument is simply anything we enter after the executable name, which in the above example is notepad.exe. So for example, if we launched Notepad using the command C:\Windows\System32\notepad.exe /s, then /s would be the command line argument we used.
Assuming the C language:
[Trying to teach you to fish, rather than providing a fish. Good luck!]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With