C++ help Dynamic array and "invalid conversion from ‘char’ to ‘char*’"
i have most of my code finished but im getting an error i dont understand "invalid conversion from ‘char’ to ‘char*’" and i need to write to a dynamic array and then output from it which i also dont know how to do. any help would be greatly appreciated. thanks for your time.
#include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; void rearrange (char *front, char *rear); int main() { string input, word; char *front, *rear; vector <string> string; cout << "Enter the string: "; getline(cin, input); istringstream break_apart(input); while (break_apart >> word) { front = &word.at(0); rear = &word.at(word.size() - 1); while (front <= rear) { rearrange (*front, *rear); // <--- heres where im getting my error front++; rear--; } cout << word << " "; } return 0; } void rearrange (char *front, char *rear) { char temp = *front; *front = *rear; *rear = temp; } |
well i was playing with it and i fixed my error but i still dont know what to for the dynamic array
|
The problem is because your rearrange function takes two char pointers: *front and *rear. However, you are dereferencing front and rear when you call the function, therefore you're passing two chars by value when the function expects two pointers. To fix it, you're going to want to change the function call to
Code:
rearrange (front, rear); |
All times are GMT -5. The time now is 11:25 AM. |