• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Can someone help me with coding? (1 Viewer)

MuffinMan

Juno 15/4/08 :)
Joined
Nov 6, 2004
Messages
3,975
Location
Liverpool, NSW
Gender
Male
HSC
2005
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;

int palindrome (int, int, char&);

int main()
{
char userInput [256]; // A very long string
char userInput2[256]; // A very long string
char temp;
char output;

cout <<"Please enter a phrase to check if it is a palindrome" << endl;
cin.getline (userInput, 256);
char tolower (char userInput);
char isspace (char userInput);

for (int a = 1; a <= 256; a++)
{
userInput[a] = temp;
temp = userInput2[256-a];
}

int palindrome (int userInput, int userInput2, char& output);

cout <<" Enter a phrase" << userInput << endl;

if (output == '1')
cout <<" It is a palindrome " << endl;
else
cout <<" This is not a palindrome " << endl;

return 0;
}

int palindrome (char userInput, char userInput2, char& output)
{
if (strcmp (userInput, userInput2) == 0) // Line 40
output = '1';
else
output = '2';
return output;
}



Compiler:

Error! Line 40. Invalid conversion from 'char' to 'const *char'

I have no idea what on earth this means
could anyone clarify this for me?
 
Last edited:

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
1) int palindrome (char userInput, char userInput2, char& output)
userInput and userInput2 are not chars. They are char arrays.

2) strcmp takes char pointers as arguments...userInput and userInput2 are not char*s, which is what the compiler is whinging about.

You should change userInput and userInput2 to char* and malloc them instead.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top