#include <stdio.h>
#include <stdlib.h>
int main()
{
char s[100],temp1[100];
int i;
printf("Some word ");
scanf("%s", s);
for (i = 0; s[i] != '\0'; ++i);
int a = i-1;
for (int k = 0; k < i; k++) {
temp1[k] = s[a];
a--;
}
printf("%s", temp1);
system("pause");
}
我正在尝试反转给定的单词,但我的答案只是得到了一些其他的东西。我知道我只能搜索它,但我想知道为什么我会那样失败,所以请帮助我。
最佳答案
您需要null
终止结果。添加
temp1[i] = '\0';
此外,将 scanf()
更改为
scanf("99%s", s);
关于c - 试图反转给定的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41000436/