C程序找错啦~

来源:百度知道 编辑:UC知道 时间:2024/06/14 15:19:40
题目要求:输入是那个长度不超过二十的字符串,把这三个字符串按照字典顺序连接,然后输出
我写的程序:
#include<stdio.h>
void main()
{
char a[20],b[20],c[20];
int t;
scanf("%s%s%s",a,b,c);
if(strcmp(a,b)>0)
{
t=a[20];
a[20]=b[20];
b[20]=t;
}
if(strcmp(a,c)>0)
{
t=a[20];
a[20]=c[20];
c[20]=t;
}
if(strcmp(b,c)>0)
{
t=b[20];
b[20]=c[20];
c[20]=t;
}
printf("%s %s %s",a,b,c);
}

t=a[20];
a[20]=b[20];
b[20]=t;
你程序毛病大着呢!
刚才给你写了那么多结果你的题目关闭了!

#include <stdio.h>
int main()
{
char a[20],b[20],c[20];
char tmp[20];
scanf("%s%s%s",a,b,c);
if(strcmp(a,b)>0)
{
strcpy(tmp, a);
strcpy(a, b);
strcpy(b, tmp);
}
if(strcmp(a,c)>0)
{
strcpy(tmp, a);
strcpy(a, c);
strcpy(c, tmp);
}
if(strcmp(b,c)>0)
{
strcpy(tmp, b);
strcpy(b, c);
strcpy(c, tmp);
}
printf("%s %s %s",a,b,c);
return 0;
}

#include<string.h>还是甚么忘了
不过是少个头文件字符串的

scanf("%s%s%s",a,b,c);
不建议这样搞,放一起容易出问题,建议改为
scanf("%s",a);
getchar();//去除回车符
scanf("%s",b);
getchar();
scanf("%s",c);
getchar();

#include <stdio.h>
void main()
{
int i,a[3][20],b[60];