there is a mistake on the code. I would like to write "test" like
t
e
s
t

but it writes reverse. it is easy but my brain is not enough.

#include <iostream.h>
#include <string.h>
#include <conio.h>

int main(void)
{
char *pointer="test";
int index;
for(index=(strlen(pointer)-1); index >= 0; index--) /* strlen="length of the string. */
cout<<pointer[index]<<endl;

cout<<"\n"<<pointer;
getch();
return 0;
}

Recommended Answers

All 3 Replies

line 9 should read
for(index=0; index < strlen(pointer); index++)
P.S. am just learning to program so this might be wrong

commented: Good start for a new programmer :) +2

I believe frogboy is correct. Your loop is decrementing instead of incrementing and hence you are printing the data with the highest index first

thank you.
your code is correct

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.