问题描述
#include <stdio.h>
void print_rev(char *s);
int main(void)
{
char *str;
str = "I do not fear computers. I fear the lack of them - Isaac Asimov";
print_rev(str);
return (0);
}
// read array and print it out backwards char by char.
void print_rev(char *s)
{
int arrLength;
arrLength = 0;
// capture length of array
while (*s != '\0') {
arrLength++;
s++;
}
arrLength--;
// print array backwards
for (; arrLength >= 0; arrLength--) {
putchar(s[arrLength]);
}
putchar('\n');
}
这是我的代码。当我运行它时,我所能做的就是让它打印出这个输出: picture of output
我尝试研究为什么会发生这种情况,但我找不到人们使用 putchar
而不是 printf
的任何视频。非常感谢帮助。
我的代码的重点是获取字符串并使用 putchar
反转它。
我无法使用函数 strlen()
。
预期输出:
vomisA caasI - meht fo kcal eht raef I .sretupmoc raef ton od I
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)