Following other inquiries I found on this site, I'm trying to print an array of pointers to characters (strings), by using a **double pointer as follows:
char *input=malloc(128), *color[7]={0}, **colors=malloc(8);
fgets(input, 128, stdin);
sscanf(input, "%s%s%s%s%s%s", &color[0], &color[1], &color[2], &color[3], &color[4], &color[5]);
color[6]=NULL;
colors=color;
while(*colors)
printf("%s ", colors++);
The output I receive from the above seems to be choking every input string down to 4 bytes and then overflowing if it is more than four, because if I type: "black red gold white green blue", for instance, I receive: "blacred red goldwhitgreeblue goldwhitgreeblue whitgreeblue greeblue blue." Very frustrating.
I tried dereferencing colors++, like I saw in other examples, but this causes the program to crash. Ultimately, the printf is just for debugging. This is part of a char ** (void) function I'm trying to create to assign what it is I'm trying to print to a local variable of type char **. How can I fix this?
malloc()is not magic...