两段计算年龄的代码,出现问题,大家给帮忙改改,小弟是在不知道问题在哪里,跪谢!
#include <time.h>
#include <stdio.h>
#include <dos.h>
void main()
{
int year,month,day;
struct date{
long year,mon,day;};
struct date *yourbirthd, *nowd;
struct tm{};
struct tm yourbirtht, nowt;
long yourbrith,now;
long resultt;
double result;
printf("\nplease input your birth date (year,month,day):\n");
scanf("%d,%d,%d",&year,&month,&day);
22) getdate(&nowd);
23) gettime(nowt);
yourbirthd->year=year;
yourbirthd->day=day;
yourbirthd->mon=month;
28) yourbirth=dostounix(yourbirthd,yourbirtht);
now=dostounix(nowd,nowt);
resultt=difftime(yourbirthd,nowd);
result=resultt/(24*60*60);
printf("\nYou hava come this world for %d days\n");
}
以上这段代码在VC++中编译出现以下错误,请问如何改正?
--------------------Configuration: 2.2 - Win32 Debug--------------------
Compiling...
2.2.cpp
E:\c\cpp2\2.2.cpp(22) : error C2065: 'getdate' : undeclared identifier
E:\c\cpp2\2.2.cpp(23) : error C2065: 'gettime' : undeclared identifier
E:\c\cpp2\2.2.cpp(28) : error C2065: 'yourbirth' : undeclared identifier
E:\c\cpp2\2.2.cpp(28) : error C2065: 'dostounix' : undeclared identifier
Error executing cl.exe.
2.2.obj - 4 error(s), 0 warning(s)
问题点数:0、回复次数:18Top
1 楼carylin(林石)回复于 2004-12-01 08:03:30 得分 0
你就没有定义这四个函数嘛Top
2 楼UP5(无纹龙)回复于 2004-12-01 11:09:50 得分 0
同意楼上的!帮顶!Top
3 楼doulikeme(来去无踪)回复于 2004-12-01 11:15:26 得分 0
那四个函数去哪里啦??????
调用了 都不知道哪里来的Top
4 楼bylmy()回复于 2004-12-01 18:40:17 得分 0
这四个函数不是分别在dos.h和time.h中定义了么???还要再怎么定义呢??Top
5 楼baichihang(白痴航)回复于 2004-12-01 18:55:59 得分 0
系统文件中定义的函数只是跟你的函数名字一样,功能完全不一样。
系统只能操作系统里面存在的系统定义的数据结构,你自己定义的结构系统函数是不能象那样进行操作的,要自己写。Top
6 楼Michael_555(Nothing)回复于 2004-12-01 19:19:05 得分 0
还有
.....................
struct tm{};
struct tm yourbirtht, nowt;
.....................
yourbirthd->year=year;
yourbirthd->day=day;
yourbirthd->mon=month;
............................
声明为一个空的结构体,但是却冒出这么多的元素来Top
7 楼milozy1983(Detective)回复于 2004-12-01 19:23:21 得分 0
如果我没猜错,楼主用vc编译这个程序的?我没看程序,但看了上面几楼的贴子感觉程序里一些函数和结构是tc里的Top
8 楼bylmy()回复于 2004-12-01 19:52:11 得分 0
现在这段程序已经在TC里通过编译,但是运行时,输入生日,回车后就没反应了,没有显示结果,不知是哪里有问题?
#include <time.h>
#include <stdio.h>
#include <dos.h>
main()
{
int year,month,day;
struct date{
long year,mon,day;
}yourbirthd, nowd;
struct time yourbirtht,nowt;
long birth;
long now;
double result;
printf("\nplease input your birth date (year,month,day):\n");
scanf("%d,%d,%d",&year,&month,&day);
getdate(&nowd);
gettime(&nowt);
yourbirthd.year=year;
yourbirthd.day=day;
yourbirthd.mon=month;
birth = dostounix(&yourbirthd,&yourbirtht);
now = dostounix(&nowd,&nowt);
result = difftime(birth,now)/(24*60*60);
printf("\nYou hava come this world for %d days\n", result);
}Top
9 楼milozy1983(Detective)回复于 2004-12-01 20:00:22 得分 0
date结构体在头文件里本来就有,time结构体用错了
struct time {
unsigned char ti_min; /* Minutes */
unsigned char ti_hour; /* Hours */
unsigned char ti_hund; /* Hundredths of seconds */
unsigned char ti_sec; /* Seconds */
};
struct date {
int da_year; /* Year - 1980 */
char da_day; /* Day of the month */
char da_mon; /* Month (1 = Jan) */
};Top
10 楼bylmy()回复于 2004-12-01 20:30:07 得分 0
那我的程序应该如何改呢?Top
11 楼yeyu170(从农民到民工)回复于 2004-12-01 20:33:43 得分 0
我感觉定义月日年应该用类,干嘛用结构?Top
12 楼sw_man()回复于 2004-12-01 20:38:39 得分 0
楼上的说得好,原因是DATE本来是标准库里的结构,被重定义了,修改后:
#include <time.h>
#include <stdio.h>
#include <dos.h>
main()
{
int year,month,day;
struct date yourbirthd, nowd;
struct time yourbirtht,nowt;
long birth;
long now;
double result;
printf("\nplease input your birth date (year,month,day):\n");
scanf("%d,%d,%d",&year,&month,&day);
getdate(&nowd);
gettime(&nowt);
yourbirthd.da_year=year;
yourbirthd.da_day=day;
yourbirthd.da_mon=month;
birth = dostounix(&yourbirthd,&yourbirtht);
now = dostounix(&nowd,&nowt);
result = difftime(birth,now)/(24*60*60);
printf("\nYou hava come this world for %d days\n", result);
}
Top
13 楼milozy1983(Detective)回复于 2004-12-01 20:40:17 得分 0
#include <time.h>
#include <stdio.h>
#include <dos.h>
main()
{
int year,month,day;
struct date yourbirthd, nowd;
struct time yourbirtht,nowt;
long birth;
long now;
double result;
printf("\nplease input your birth date (year,month,day):\n");
scanf("%d,%d,%d",&year,&month,&day);
getdate(&nowd);
gettime(&nowt);
yourbirthd.da_year=year;
yourbirthd.da_day=day;
yourbirthd.da_mon=month;
birth = dostounix(&yourbirthd,&yourbirtht);
now = dostounix(&nowd,&nowt);
result = difftime(birth,now)/(24*60*60);
printf("\nYou hava come this world for %d days\n", result);
}Top
14 楼bylmy()回复于 2004-12-01 21:04:36 得分 0
谢谢两位!!现在编译在TC下已经通过,运行没看到结果就不见了。但是在VC下编译就10个错误,不知道为什么会出现这样的情况?VC和TC有什么差别呢?
Top
15 楼bylmy()回复于 2004-12-01 21:10:24 得分 0
这是VC下编译出现的错误:\--------------------Configuration: 2.2 - Win32 Debug--------------------
Compiling...
2.2.cpp
E:\c\cpp2\2.2.cpp(8) : error C2079: 'yourbirthd' uses undefined struct 'date'
E:\c\cpp2\2.2.cpp(8) : error C2079: 'nowd' uses undefined struct 'date'
E:\c\cpp2\2.2.cpp(9) : error C2079: 'yourbirtht' uses undefined struct 'time'
E:\c\cpp2\2.2.cpp(9) : error C2079: 'nowt' uses undefined struct 'time'
E:\c\cpp2\2.2.cpp(17) : error C2065: 'getdate' : undeclared identifier
E:\c\cpp2\2.2.cpp(18) : error C2065: 'gettime' : undeclared identifier
E:\c\cpp2\2.2.cpp(19) : error C2228: left of '.da_year' must have class/struct/union type
E:\c\cpp2\2.2.cpp(20) : error C2228: left of '.da_day' must have class/struct/union type
E:\c\cpp2\2.2.cpp(21) : error C2228: left of '.da_mon' must have class/struct/union type
E:\c\cpp2\2.2.cpp(23) : error C2065: 'dostounix' : undeclared identifier
Error executing cl.exe.
2.2.obj - 10 error(s), 0 warning(s)Top
16 楼milozy1983(Detective)回复于 2004-12-01 21:17:04 得分 0
加个getch()吧,vc不全部支持borland的函数库,一些函数是16位调用中断写的,vc的程序是保护模式下的,不支持中断
#include <time.h>
#include <stdio.h>
#include <dos.h>
main()
{
int year,month,day;
struct date yourbirthd, nowd;
struct time yourbirtht,nowt;
long birth;
long now;
double result;
printf("\nplease input your birth date (year,month,day):\n");
scanf("%d,%d,%d",&year,&month,&day);
getdate(&nowd);
gettime(&nowt);
yourbirthd.da_year=year;
yourbirthd.da_day=day;
yourbirthd.da_mon=month;
birth = dostounix(&yourbirthd,&yourbirtht);
now = dostounix(&nowd,&nowt);
result = difftime(birth,now)/(24*60*60);
printf("\nYou hava come this world for %d days\n", result);
getch();
}
Top
17 楼bylmy()回复于 2004-12-01 21:22:54 得分 0
加了getch(),已经好了,太感谢了。Top
18 楼bylmy()回复于 2004-12-01 21:25:01 得分 0
送分给你Top




