Wednesday 15 January 2014

C Program skips the loop in this program in gcc compiler -



C Program skips the loop in this program in gcc compiler -

hi can see why programme not printing reverse of sting. used gcc compiler : gcc (ubuntu 4.8.2-19ubuntu1) 4.8.2.

#include <stdio.h> #include <string.h> void print_reverse(char *s) { size_t len = strlen(s); char *t = s + len -1; // believe programme skipping loop don't know why... while (t <= s){ printf("%c", *t); t = t - 1; } puts(t); } int main() { char *juices[] = { "dragonfrui", "waterberry", "sharonfruit", "uglifruit", "rumberry", "kiwifruit", "mulberry", "strawberry", "blueberry", "blackberry", "starfruit", }; print_reverse(juices[0]); printf("%s\n", juices[0]); homecoming 0; }

your guess correct. remember t moving end beginning, so

while (t <= s){

should be

while (t >= s){

c

No comments:

Post a Comment