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

Hi all C experts (please don't shoot, I'm no C programmer anymore but from time to time I have a question that pops in my mind)

I was reading another question (How to print an entered string backwards in C using only a for loop).

The "simplest" and most logical answer is

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

But I was wondering if there wasn't a way to achieve the same goal but staying closer to the original loop poseted:

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

I don't know enough C to work it out, but couldn't we play with the arrays pointers to loop through

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

P.S.: I don't really care if it is a forwards or backwards loop.

P.P.S.: Sorry if I made obvious C mistakes in the pointers; point them out in the comment and I'll edit them. ;)

Jason

Answers


Absolutely.

char *wordp;

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

Need Your Help

List of Loaded iptables Modules

iptables

Is there any convenient way to show loaded iptables module list? I can show installed modules by listing /lib/iptables/ (or /lib64/iptables/) directory but I need active module list.

Swipe pdf pages in horizontally in android

android

I am developing an android application based on pdf reader so i got opensource pdf reader like

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.