Oh thanks a lot, it makes sense
And it obviously returned "true" because the char '\0' marks the end of the string.
Code: #include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]);
int main(int argc, char *argv[]) {
char n_input[99];
int n;
fgets(n_input, sizeof n_input, stdin);
sscanf(n_input, "%d", &n); //get the number of times out of n_input to n
char ** all_input[n];
char * two_numbers[2];
int i;
char input[100];
char * saveptr1;
for(i=0; i<n; i++) {
fgets(input, sizeof input, stdin);
strtok_r(input, " ", &saveptr1);
two_numbers[0] = input;
two_numbers[1] = saveptr1;
all_input[i] = two_numbers;
}
My goal is to get input like:
Quote:
2
12 19
21 30
And then have an array like:
Quote:
{ {"12", "19"}, {"21", "30"} }
However, what I get on the array is:
Quote:
{ {"21", "30"}, {"21", "30} }
I don't quite see why this is happening, because:
Code:
fgets(input, sizeof input, stdin);
strtok_r(input, " ", &saveptr1);
two_numbers[0] = input;
two_numbers[1] = saveptr1;
all_input[i] = two_numbers;
I'm adding "two_numbers" in "all_input[i]", so the elements before [i] shouldn't change to "two_numbers" too.
Unless if this is a memory problem, and I need to allocate memory or something.