大学定向越野好过吗:谁帮我看看这个C程序哪里错了

来源:百度文库 编辑:高考问答 时间:2024/04/30 03:39:20
#include <stdio.h>
#include <dos.h>
void delay();
void update();
void display();
struct tm
{
int hours,minites,seconds;
};
main()
{
struct tm time;
time.hours=0;
time.minites=0;
time.seconds=0;
for(; ;)
{
update(&time);
display(&time);
}
}
void update(struct tm *t)
{
(*t).seconds++;
if((*t).seconds==60)
{
(*t).seconds=0;
(*t).minites++;
}
if((*t).minites==60)
{
(*t).minites=0;
(*t).hours++;
}
if((*t).hours==24) (*t).hours=0;
delay();
}
void display(struct tm *t)
{
printf("%d:",(*t).hours);
printf("%d:",(*t).minites);
printf("%d:\n",(*t).seconds);
}
void delay()
{
long int t;
for(t=1;t<128000;t++);
}
编译出现这样的错误
Error c:\COUT\TEST.C 36:Too few parameters in call to 'delay' in functoin up
我是在turboc2.0编译的
我以经把delay改成ffff了,还是不行啊!!
感谢各位的帮忙,但改来改去还是报共一个错误

似乎tc已经有个函数叫delay了,需要带参数,你试试把你定义的delay函数改名看看。或者干脆用tc自带的delay延迟一定毫秒算了,就不用那个for循环了

ps: 你改成ffff没有通过是因为你没有替换所有的,我替换全部之后就通过了。好像三个地方要替换:上面声明的地方、调用的地方、函数定义的地方。

你想用那个DELAY函数来做什么呢

注意你的函数参数申明和定义不一样呵呵,下面测试通过,记得delay的128000再大些吧在我机器上太快了~^Q^
#include <stdio.h>
#include <dos.h>
struct tm
{
int hours,minites,seconds;
};
void delay();
void update(struct tm*);
void display(struct tm*);
main()
{
struct tm time;
time.hours=0;
time.minites=0;
time.seconds=0;
for(; ;)
{
update(&time);
display(&time);
}
}
void update(struct tm *t)
{
(*t).seconds++;
if((*t).seconds==60)
{
(*t).seconds=0;
(*t).minites++;
}
if((*t).minites==60)
{
(*t).minites=0;
(*t).hours++;
}
if((*t).hours==24) (*t).hours=0;
delay();
}
void display(struct tm *t)
{
printf("%d:",(*t).hours);
printf("%d:",(*t).minites);
printf("%d:\n",(*t).seconds);
}
void delay()
{
long int t;
for(t=1;t<128000;t++);
}

上面的也通不过,如果是自带的delay()需要带参数,你可以把延迟时长直接设为delay()的参数即可。
如果你要自己定义就不要用#include <dos.h>
这个头文件。

delay函数中需要指明延迟的时间,以毫秒为单位。