cstring and pointers

ok after few times of testing i think i am a step closer check this out.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<iostream>
#include<cstring>
using namespace std;



int main(void) 
{
	char temp[20];
	cout<<"input something";
	cin>>temp;
	char* name = temp;  // pointer to string

	cout << "The second letter in name is " << *(name+1) << ".\n";
	
   


}


this code display the second element of what you input. E.G if u you keith it will cout "e" So bascially i can locate each letter, what i need now is a for loop that will display the whole name backwards, anyone got any idea. and if i do name+1 it will display eith.

My proposal is to use a link list that the last node point back to the first node, and somehow right a function to test which node is the first node then decrement it till the last node while writing a recursion to display it. my problem about my proposal is 1. i think i am overkilling it, 2. i don't know how to test which one is head node if i point my last node to the head node.
Why don't you just iterate through the string printing each character at a time in reverse order?
i am required to use pointer in this code.
Then iterate with a pointer:

1
2
3
for(char *ptr = temp[strlen(temp) - 1]; ptr >= temp; --ptr) {
    std::cout << *ptr;
}
Topic archived. No new replies allowed.