《输入字符串,倒序输出》无法正确输出结果
毕业设计
1
#include <stdio.h>
int main()
{
printf("请输入要倒序的内容\n");
char s = scanf("%c");
char a[65536] = {'\0'};
a[65536] = s;
char *t = &a[0];
int len = 0;
while (*t != '\0')
{
printf("第%d个字符:%c\n",len,*t);
len++;
t++;
}
printf("共计%d个字符\n", len);
for (int i=len;i>0;i--)
{
printf("%c",*t);
t--;
}
return 0;
}
-
#include <stdio.h> int main() { printf("请输入要倒序的内容\n"); char s [65536]; scanf("%s",s); //获取一个字符串放入数组s中 char *t = &s[0]; //用一个字符指针指向这个字符串开头 int len = 0; while (*t != '\0') { printf("第%d个字符:%c\n",len,*t); len++; t++; } printf("共计%d个字符\n", len); for (int i=len-1;i>=0;i--) //逆序打印 { printf("%c",s[i]); } return 0; }
-
#include <stdio.h> #include <string.h> int main() { printf("请输入要倒序的内容\n"); char s[250]; gets(s); char a[65536] = {'\0'}; int len = strlen(s),j; for (j=0; j<len; j++) { printf("第%d个字符:%c\n",j+1,s[j]); } printf("共计%d个字符\n", len); for (int i=len-1; i>=0; i--) { printf("%c",s[i]); } return 0; }
发表回复