c语言排序问题?

来源:百度知道 编辑:UC知道 时间:2024/05/12 07:03:57
输入一串字符
用for,if语句编代码
倒着输出
不限制出入的字符多少
怎么编原代码啊?
谢谢!

来吧,这个应该可以完美的解决你的问题 ^_^
#include <stdio.h>

void invert(char s[], int n);

int main(int argc, char *argv[])
{
int len;
char buf[1024], *tmp=NULL;
memset(buf, 0, sizeof(buf));

while( 1 )
{
printf("%x : Please input string (^C to exit): ", &buf);

tmp = fgets(buf, sizeof(buf), stdin);

len = strlen(tmp);
if( len>1 )
{
tmp[len-1] = '\0';
invert(tmp, strlen(tmp));
fputs(tmp, stdout);
fputs("\n", stdout);
}
}

return 0;
}

void invert(char s[], int n)
{
char temp;
if(n>1)
{