Why cant i read the second value from command line using this code, i am using VS 2017 and have 4+3 in the command arguments
#include <stdio.h>
int main(int argc, char *argv[])
{
float numberOne;
float numberTwo;
float theResult;
if (argc == 2)
{
sscanf(argv[1], "%f", &numberOne);
sscanf(argv[2], "%f", &numberTwo);
printf("%f \n", numberOne + numberTwo);
}
else
{
printf("invalid input");
}
sleep(10);
return(0);
}
argc == 2
the valid indices are[0]
and[1]
, the value 2 says how many there are, not the highest index. And if you input4+3
, without spaces, I would expect all of it inargv[1]
. – Bo Persson Oct 21 '17 at 12:31sscanf()
too. – Jonathan Leffler Oct 21 '17 at 14:40