0

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.

3
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by Aia
0

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

0

I would start with this:

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

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

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?

0

[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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.