New to C, still getting a grasp on pointers. I'm trying to add a copy of a c string into a char array such that
char temp[40];
temp[0] = 'a';
temp[1] = 'b';
temp[2] = 'c';
temp[3] = NULL;
char *container[40] = {0};
strcpy(container[0], temp);
cout << container[0] << endl;
prints "abc". Trying to make a copy because temp is constantly being replaced with new characters and a pointer to temp obviously won't suffice as i want to do this after abc is printed.
char temp[40];
temp[0] = 'd';
temp[1] = 'e';
temp[2] = 'f';
temp[3] = NULL;
char *container[40] = {0};
strcpy(container[1], temp);
cout << container[1] << endl;
prints 'def'. P.S this is what i have so far, but it doesn't work. I'm not too sure if im using strcpy incorrectly, but any alternatives would be helpful.
container[0]is just a pointer to achar. You must point it to enough memory before you callstrcpy.chararray....