Is there a way in C to store the whole command line options and arguments in a single string. I mean if my command line is ./a.out -n 67 89 78 -i 9 then a string str should be able to print the whole command line. Now, what I am able to do is to print values in different vector forms.
#include <stdio.h>
#include <getopt.h>
#include <string.h>
int main(int argc, char* argv[]) {
int opt;
for(i=0;i<argc;i++){
printf("whole argv was %s\n", argv[i]);
}
while((opt = getopt(argc, argv, "n:i")) != -1) {
switch (opt){
case 'n':
printf("i was %s\n", optarg);
break;
case 'i':
printf("i was %s\n", optarg);
break;
}
}
return 0;
}
I want this, as optarg only is printing my first argument and I want all the arguments to be printed, so I want to parse it after storing it in string.
./a.out foovs./a.out "foo"; your program can't know if the user quoted an argument.