does anyone know how to give the characters of a string numeric variables? so when i can print the numeric variables in decending order so the word is read backwards?
for example
hello h=1 e=2 l=3 l=4 0=5
olleh

your help would be very appreciated, a snippet would be awesome, or a written code would be very great.

Recommended Answers

All 6 Replies

enum will allow you to do that.

A string is basically just an array, why can't you simply start an index at the end and count down?

how would one do that?

I would start with this:

const char *s = "hello";
int i;

for ( i = 4; i >= 0; i-- )
  putchar ( s[i] );

Notice that Narue said start.
Unless you are working only with strings of four characters plus '\0' all the time, you'll see that for loop needs some more logic.
How can you figure before hand what the length of the string is to pass it to the for loop?

[erratum:]
>Unless you are working only with strings of four characters plus '\0' all the time

Since this might confuse the Original Poster I must correct myself. "Hello" is composed of five characters and the string terminator, and not four characters as previously stated.

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.