Inserting c_str into char*

How do I take a c string and input it into a char* array? Basically I want to take a few sentences and add them one at a time into a char array.

Example:

1
2
3
4
5
6
char* userInputArray[500];
string str1 = "This is a test sentence";
string str2 = "Middle sentence goes here";
string str3 = "End sentence";
//I actually have a loop to collect input and convert each
//string to a c_string but that's not relevant to my issue. 


I want to put sentence 1 in the char*, then the second, then the third.

I tried something like this:
 
*userInputArray = *userInputArray + str1;


Now I know that won't work but I'm not sure what I can do to accomplish this goal.

Any advice?

Thanks!
Last edited on
1. userInputArray is not a character array, it is an array of pointers.
2. Why do you want to do this?
It's for an assignment. I'm not sure what I'm doing and have been having a hard time wrapping my brain around the assignment. He wants us to create a buffer that contains three sentences as described up above and wants us to use pointers to display the sentences back to the user in reverse order. I guess the char* is to house the addresses of where each sentence starts in the buffer? What should I use as a buffer a char array separating each sentence with a null?
Last edited on
You can make a pointer point to the address of a specific array element

1
2
3
4
5
6
7
8
9
10
const int MAX = 500;

int main(){

	char userInput[MAX];

	char* ptr = &userInput[25];
		
	return 0;
}
Last edited on
Topic archived. No new replies allowed.