I'm trying to run a simple calculator program by passing it the numbers and the operation from the command line, such as "25.2 + 4.87". It works fine when using the default values but once I pass in the arguments, it throws the following message: "Exception thrown: read access violation. argv was 0xFEFEFEFE"
Here's the code:
//Valores por default
char num1[] = "0.5";
char num2[] = "10.25";
char operacion = '/';
if (argv[1] && argc ==4) {
std::cout << argv[1] << std::endl;
std::cout << argv[2] << std::endl;
std::cout << argv[3] << std::endl;
strcpy_s(num1, 100, argv[1]);
strcpy_s(num2, 100, argv[3]);
operacion=*argv[2];
}
It prints out the arguments fine but after running the program it throws the error I mentioned earlier after executing the second strcpy_s:
strcpy_s(num2, 100, argv[3]);
The first strcpy_s works fine and num1 gets assigned the first number I passed in the arguments, but anything else I do after that throws the error.
While debugging line by line I noticed that the variable "argv" has the correct path for my executable file, but after executing the first strcpy_s, the content changes from the correct file path to 0xfefefefe
I've looked for this error but all of them had a nullptr error, I couldn't find any information on this. I would greatly appreciate your help, thanks.