algorithm - Loops in C challenge: can it be done another way? -


hi c experts (please don't shoot, i'm no c programmer anymore time time have question pops in mind)

i reading question (how print entered string backwards in c using loop).

the "simplest" , logical answer

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

but wondering if there wasn't way achieve same goal staying closer original loop poseted:

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

i don't know enough c work out, couldn't play arrays pointers loop through

char * wordp; for(wordp = &word[end]; /*something*/; wordp--){\    printf("%c", &wordp); } 

p.s.: don't care if forwards or backwards loop.

p.p.s.: sorry if made obvious c mistakes in pointers; point them out in comment , i'll edit them. ;)

jason

absolutely.

char *wordp;  for(wordp = word + end; wordp >= word; wordp--){    printf("%c", *wordp); } 

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? -