LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-25-2009, 09:13 PM   #1
heathf
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
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;
}
 
Old 04-25-2009, 09:15 PM   #2
heathf
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
well i was playing with it and i fixed my error but i still dont know what to for the dynamic array
 
Old 04-25-2009, 09:20 PM   #3
ilikemonkeys111
LQ Newbie
 
Registered: Mar 2009
Distribution: archlinux
Posts: 6

Rep: Reputation: 1
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);
That should fix your problem :-{D
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with "error: invalid conversion from `const char*' to `char*' " dave.f.one Linux - Newbie 10 11-19-2008 10:01 AM
about C++ invalid conversion from 'const char*' to 'char' teoporta Programming 3 07-17-2007 09:24 AM
invalid conversion from `const char*' to `char*' deepinlife Programming 22 08-05-2006 10:49 AM
If I get invalid conversion from `const char*' to `char' what should I be lookin for? RHLinuxGUY Programming 5 03-12-2006 10:35 PM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM


All times are GMT -5. The time now is 01:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration