I am trying to read user input from the terminal. If I enter "one two three four", how can I store these strings into argvs like argv[0] == one, argv[1] == two, argv[2] == three, argv[3]== four .. using fgets?
I am trying to read user input from the terminal. If I enter "one two three four", how can I store these strings into argvs like argv[0] == one, argv[1] == two, argv[2] == three, argv[3]== four .. using fgets?
fgets reads a whole line only. You will have to break the line up into words using something like strtok. Google for examples. If you need more complex parsing of the line, it would probably be best to write your own state machine.
argv[] is used for command line input. If you wanted to do it that way, you will not need fgets
Command Line Arguments in C - Cprogramming.com
If you wanted to use fgets, you will have to create your own 2D array and use strtok + strncpy to enter your strings.
C Strings - Cprogramming.com
Fact - Beethoven wrote his first symphony in C
This may help.Code:int get_number() { char buffer[100]; //array that we are going to store the number in. int num; fgets(buffer, 100, stdin) sscanf(buffer, "%d", &num) return num; }
That is putting your number into a char array, then converting it to an integer. (num).
Ahh, sorry. I completely read that wrong. I was thinking he needed help with something else.