I've research for half a day and cannot figure out how to pass a simple char pointer, and modify the value in a function. Most of the solutions say to modify the function to accept a char **
parameter.
I have a function I cannot modify. I need to pass a char pointer to it because this function will give me a new calculated char value. I was told I can pass a pointer to a char array and it will work, but I am unsure how to do it.
Passing char pointer as argument to function
I followed the above post and came up with the following code but it still does not work. When I pass the pointer to the char arr[] it does not change its value. My goal is to pass a char pointer and be able to write to it in another function by passing its reference. Any help is appreciated.
enum STATUS {
OK = 0,
BAD = 1,
};
STATUS func1(char *pData)
{
pData = "Hello World";
cout << pData << endl;
return OK;
}
int main()
{
STATUS ret;
char arr[] = "Example String";
char* pArray = &arr[0];
ret = func1(pArray);
cout << arr << endl;
cout << pArray << endl;
getchar();
return 0;
}