C程序在gcc编译器中跳过此程序中的循环

时间:2014-11-02 03:15:06

标签: c

嗨,任何人都可以看到为什么我的程序没有打印出刺痛的反面 我使用了gcc编译器: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;

    // I believe my Program is skipping this 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]);
    return 0;
}

1 个答案:

答案 0 :(得分:2)

你的猜测是正确的。请记住,t正在从结尾移动到开头,所以

while (t <= s){

应该是

while (t >= s){