C 求纠错

来源:百度知道 编辑:UC知道 时间:2024/06/30 22:56:37
#include<stdio.h>
void main()
{
int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
void sort(int *,int *,int *);
int *p1=&a;
int *p2=&b;
int *p3=&c;
sort(p1,p2,p3);
}

void sort(int *x,int *y,int *z)
{
int *t;
if(*x>*y)
t=x,x=y,y=t;
if(*x>*z)
t=x,x=z,z=t;
if(*y>*z)
t=y,y=z,z=t;
printf("the sorted numbers are:\n");
printf("%d %d %d\n",*x,*y,*z);
}
c(6) : error C2143: syntax error : missing ';' before 'type'
c(7) : error C2143: syntax error : missing ';' before 'type'
c(8) : error C2143: syntax error : missing ';' before 'type'
c(9) : error C2143: syntax error : missing ';' before 'type'
c(10) : warning C4013: 'sort' undefined; assuming extern returning int
c(10) : error C2065: 'p1' : undeclared identifier

你这是C程序吧,那么变量的定义都只能放在函数的首部:
#include<stdio.h>
void main()
{
int a,b,c;
void sort(int *,int *,int *);
int *p1=&a;
int *p2=&b;
int *p3=&c;
scanf("%d,%d,%d",&a,&b,&c);
sort(p1,p2,p3);
}

void sort(int *x,int *y,int *z)
{
int *t;
if(*x>*y)
t=x,x=y,y=t;
if(*x>*z)
t=x,x=z,z=t;
if(*y>*z)
t=y,y=z,z=t;
printf("the sorted numbers are:\n");
printf("%d %d %d\n",*x,*y,*z);
}

可以运行啊~虽然sort函数里面的 判断语句写的不太好,但是也没有错啊
后缀改成 .cpp 或者按照下面改
你用的是VC6.0?
#include<stdio.h>
void main()
{
int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
void sort(int *,int *,int *);
int *p1=&a;
int *p2=&b;
int *p3=&c;
sort(p1,p2,p3);
}

改成

#include<stdio.h>
void main()
{
int a,b,c;
int *p1=&a;
int *p2=&b;