Help With Pointers

Im working a a program that uses pointers to check if a word is a palindrome or not. I know the code needs to have the pointers go through the array one starting at the beginning and one at then end comparing the chars to see if they are equivalent. I'm wondering where I need to go from here?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 #include <iostream>
using namespace std;

bool isPalindrome(const char *);

int main()
{
	char x[100];
	cout << "Enter a word or phrase: ";
	cin.getline(x,100);
	
	if(isPalindrome(x))
		cout << "This is a palindrome.\n";
	else
		cout << "This is NOT a palindrome.\n";

	return 0;
}

bool isPalindrome(const char * xPtr)
{
	bool result = true;
	const char * endPtr = xPtr;

	// loop to move endPtr to the NULL character in the string
	for ( ; *endPtr != NULL; endPtr++)
	{

	}
		
			
	

	// move endPtr to the character before the NULL
	endPtr--;

	// loop to check for not a palindrome
	// each time in the loop, increment xPtr and decrement endPtr
	
	for ( ; *xPtr != *endPtr; *xPtr++, *endPtr--) 
	
	


	return result;
}


  
I know the code needs to have the pointers go through the array one starting at the beginning and one at then end comparing the chars to see if they are equivalent.

Not really. You can think of the string as an array and index into that array using integers.
Topic archived. No new replies allowed.