[求助]新手上路,输入任意数目的字母要求编一程序使它倒输
输入任意个数的字母要使它们倒着输出来,比如我输入
hello
它输出的结果为
olleh
我输入
congratulationg
它输出的结果为
gnoitalutargnoc
[CODE]
#include <stdio.h>
#include <conio.h>
void main()
{
char p[50],*q;
gets(p);
q=strlen(p)+p-1;
while(q>=p)
printf("%c",*q--);
getch();
}
[/CODE]
我没有看懂main函数调用!=10 这是什么道理?
#include<stdio.h>
#include<string.h>
void main()
{
char a[100];
int i=0;
while(a[i]!='\n')
{
i++;
scanf("%c",&a[i]);
}
a[i]='\0';
for(i=strlen(a);i>=0;i--)
printf("%c",a[i]);
printf("\n");
}
注意把没有输入任何字符的之中用a[i]='\0'来负值。不然会输出内存里默认的字符。
我按你写的程序输进去根本就没输出任何东西。
而且我现在是要求会出现出错提示[此贴子已经被作者于2006-3-29 16:59:44编辑过]