W
william
I wonder how 'main(int argc, char ** argv)' is implemented? How
does it get
the string literals separated by whitespace from the stdin stream?
And is there any difference between 'char**' and 'char *[ ]'(the
second argument of function main)?
My initial purpose was to parse the input from the keyboard like
'main' does, code is here:
#include <stdio.h>
#include <string.h>
.......(omitted)
char input[256];
char * token;
printf("/> ");
scanf("%s", input);
token=strtok(input, ' '); //use whitespace as delimiter;
^using this line, I intent to parse the input from keyboard into
different tokens(which will be arguments for my further use)
****************
However, the problem was, I found 'scanf' can only get the first
string ending with '\0'. For example, if I type "command arg1 arg2
arg3" following the hint "/> " that I printed, scanf can only get
command into the array 'input', and all arg1, arg2... are truncated.
And thus my purpose can not be reached by token=strtok(input, ' ')
repeatedly, because input has only 'command\0'.
Can anyone tell me how I can implement this: get and parse the user
input conveniently? Thank you
does it get
the string literals separated by whitespace from the stdin stream?
And is there any difference between 'char**' and 'char *[ ]'(the
second argument of function main)?
My initial purpose was to parse the input from the keyboard like
'main' does, code is here:
#include <stdio.h>
#include <string.h>
.......(omitted)
char input[256];
char * token;
printf("/> ");
scanf("%s", input);
token=strtok(input, ' '); //use whitespace as delimiter;
^using this line, I intent to parse the input from keyboard into
different tokens(which will be arguments for my further use)
****************
However, the problem was, I found 'scanf' can only get the first
string ending with '\0'. For example, if I type "command arg1 arg2
arg3" following the hint "/> " that I printed, scanf can only get
command into the array 'input', and all arg1, arg2... are truncated.
And thus my purpose can not be reached by token=strtok(input, ' ')
repeatedly, because input has only 'command\0'.
Can anyone tell me how I can implement this: get and parse the user
input conveniently? Thank you