I have some strings stored inside a 2D character array like that:
char** strings = malloc(4*sizeof(char*));
strings[0] = "this:is,an,example\n";
strings[1] = "another:example\n";
strings[2] = "hello:dear,world\n";
strings[3] = "thank:you,for,help\n";
Now I'd like to take a specific substring from each of these strings and store them inside another 2D character array. Let's say I want every substring of this until seeing a ':'
character. How can this be done without causing memory access violation? I have tried it like this but I get the violation :(
char** substrings = malloc(4*sizeof(char*));
for(int i=0; i<4; i++) {
for(int j=0; strings[i][j] != ':'; j++) {
substrings[i][j] = strings[i][j];
}
}
free(strings);
free(substrings);