Pointers and Palindromes

I need help with homework assignment for my Computer Science 2 course. We are learning about pointers and so this assignment focuses on that. My professor wanted me to use character pointers for the two strings but I can't seem to grasp character pointers so I tried string pointers because that seemed more logical since I was dealing with strings but I'm still getting error messages. I'm suppose to get the two strings from the user, determine the length of each string, determine if its a palindrome, then reverse it, then concat them and display all of that. If anyone can give me some advice it would be appreciated.

void getStrings(string *firstline, string *secondline, string dummy)
{

cout << " Please enter the first string: ";
getline (cin, *firstline);

getline (cin, dummy);

cout << " Please enter the second string: ";
getline(cin, *secondline);

}

void getLength (string *firstline, string *secondline)
{
cout << sizeof(firstline);
cout << sizeof(secondline);
}
Use the char pointers as told. All pointers are pointers, but std::string is definitely not a char.

Were you told about C-strings? The convention that a '\0' character marks the end of an array of chars.


Do not make functions that do two things. Make a function that does one thing only.

For example, determines the length of a C-string. Return the value -- do not print anything from such function. Then you can call that function once for each C-string that you have.
Okay, so I changed it and attempted char pointers and it's going okay so far.

Does it look like I'm on the right track?

void getStrings()
{
char str1 [30];
char str2 [30];
string dummy;

cout << " Please enter the first string: ";
cin.getline (str1, 30);

cout << " Please enter the second string: ";
cin.getline (str2,30);

}

void getLength (char str1[], char str2[])
{
char *one = str1;
char *two = str2;

int length = 1;
while (*one!= '\0')
{
length++;
one++;

}
int length2 = 1;
while (*one!= '\0')
{
length2++;
one++;

}


}

void isPalindrome (char *one, char *two)

{

if (
No.

Make first a program that takes one string, determines the length of that string, determines if its a palindrome, and reverses it.
Topic archived. No new replies allowed.