0
I am making a code that should receive two strings for the execution with the parameters -i and -o, both of which can be null or not,the problem is found when the value of -i is not informed, it takes -o as argument.
while ((option = getopt (argc, argv, "i:o:")) != -1)
switch (option)
{
case 'i':
value_i = optarg;
break;
case 'o':
value_o = optarg;
break;
default:
fprintf (stderr, "Usage: %s -i value -o value\n", argv[0]);
exit (1) ;
}
printf ("value_i = %s, value_o = %s \n", value_i, value_o);
The expected result of . /read -i -o hello would be that i = NULL and o = hello, but results in i = it and o = NULL