# Thread: Pointers and Strtok Help

1. ## Pointers and Strtok Help

You are going explore how to check if asentence is symmetric!

For example, the following sentences aresymmetric: (read the sentence from left to right and from right toleft they are the same, of course ignore the punctuation marks).

- “I am, am I?”
- “Booboo is booboo.”
- “Life is hard!! Hard is life”

In your design, you should fully explore the use of pointer and itsarithmetic.

Using the notation, for example str [k] or *(str + k) toaccess to kth is not allowed; you should however move a pointerrelated to str to kth position, dereferencing it to get its content.

Steps:
- Get the 1st and the last words of the array

- If they are not equal, game over

- If they are the same, remove the 1st word and the lastword, if any. When we say remove … means we closethe gap of the array. For example, if we wish to removethe first element, we move the 2nd element to theposition of the 1st element; we move the 3rd element tothe position of the 2nd element and etc. In this situation,the size of the original array will be reduced by one.

- We repeat the above until the size of the array isreduced to one or zero.

1. How do I do this.....remove the first element, we move the 2nd element to the position of the 1st element; we move the 3rd element to the position of the 2nd element and etc?

2. How can I move a pointer to a specific location and deference it? I just started to learn pointer, hope any pros here can give me some directions.

2. Using the notation, for example str [k] or *(str + k) toaccess to kth is not allowed; you should however move a pointerrelated to str to kth position, dereferencing it to get its content.
Am not sure I got the restriction quite right. Am going to give an example with how a simple implementation of strcmp works hope you can apply this to your problem. It should only be a slight modification.

Code:
```int strcmp(const char *lhs, const char *rhs)
{
while(*lhs && (*lhs == *rhs))
lhs++;
rhs++;

return *lhs - *rhs;
}```
Probably not the best example out there but the important thing is the pointer arithmetic. If you increment a pointer it points to the next element in the array.

In you case you should have a pointer pointing to the last item in the string while another one points to the first then decrement one while incrementing the other and comparing until
-The pointers are equal, that is, the point to the same location in the string, in which case the string will be symmetrical.
-Until the characters pointed to by the pointers do not match in which case the string will not be symmetrical.

Edit: Well, I see you mention strtok in the topic but nowhere in the problem description. Do you have a requirement to use strtok ?