arrays - How to print an entered string backwards in C using only a for loop -


i want print string backwards. code seems count down alphabet last letter in array first letter in array instead of counting down array , spitting out each letter in array.

my code,

   #include <stdio.h>    #include <string.h>     int main(void) {  char word[50]; char end; char x;  printf("enter word , i'll give backwards: ");  scanf("%s", word);  end = strlen(word) - 1;  (x = word[end]; x >= word[0]; x--) {     printf("%c", x); }  return 0; } 

any suggestions? thank you.

what have loops between array element values. want loop between array indexes. update loop following:

for (x = end; x >= 0; --x) {     printf("%c", word[x]); } 

note goes last index 0 , output character @ index. micro-optimization in loop using pre-decrement.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -