嗨,任何人都可以看到为什么我的程序没有打印出刺痛的反面
我使用了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;
}
答案 0 :(得分:2)
你的猜测是正确的。请记住,t
正在从结尾移动到开头,所以
while (t <= s){
应该是
while (t >= s){