#include<reg52.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
void init_uart() //串口初始化
{
SCON = 0x40;
PCON = 0;
REN = 1;
TMOD = 0x20;
TH1 = 0xfd;
TL1 = 0xfd;
TI = 1;
TR1 = 1;
}
void swop(uint *p1,uint *p2)
{
uint temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
void main()
{
uint x,y;
uint *p_x,*p_y;
init_uart();
p_x = &x;
p_y = &y;
while(1)
{
printf("please input two number
");
scanf("&d&d",&x,&y);
if(*p_x < *p_y)
swop(p_x,p_y);
printf("seriation %d %d
",*p_x,*p_y);
}
}
如上,代码是进行排序输出的。可是,发现输入的两个数并没有排序,而是仅仅按照我的输入顺序排序的,请教下坛友,我的代码哪有错误呢?
此帖出自
小平头技术问答
#include<stdio.h>
void swop(int *p1,int *p2)
{
int temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
void main()
{
int x = 0,y = 0;
int *p_x,*p_y;
p_x = &x;
p_y = &y;
printf("please input two number ");
scanf("%d %d",&x,&y);
if(*p_x < *p_y)
swop(p_x,p_y);
printf("seriation %d %d ",*p_x,*p_y);
}
这个在VC下实现没问题。
注意你的scanf语句。&d?。。
一周热门 更多>