当前位置: 代码迷 >> C语言 >> "stdlib.h","math.h"和"time.h"
  详细解决方案

"stdlib.h","math.h"和"time.h"

热度:1188   发布时间:2006-10-12 00:18:10.0
"stdlib.h","math.h"和"time.h"
#include"stdlib.h"
#include "math.h"
#include "time.h"
都有什么用?
搜索更多相关的解决方案: math  stdlib  time  include  

----------------解决方案--------------------------------------------------------

这些都是些库文件,里面有你能用的函数!


----------------解决方案--------------------------------------------------------
具体一点嘛

----------------解决方案--------------------------------------------------------

math.h是数学函数头文件可以帮助求一些运算的例如开方,取模,求绝对值等 具体包含哪些数学函数和使用方法你可以查查书的

stdlib.h 是系统函数头文件包括exit 和itoa

exit是结束程序且返回值将被忽略
原型: void exit(int retval);

程序代码:


#include <stdlib.h>

main()
{
int i;
for(i=0;i<10;i++)
{
if(i==5) exit(0);//结束程序
else
{
clrscr();
printf(\"%d\",i);
getchar();
}
}

getchar();
return 0;
}




itoa是把整数i转换成字符串,返回指向转换后的字符串的指针
原型:char *itoa(int i);

例如:
程序代码:
#include <stdlib.h>

main()
{
int i=7412;

printf(\"%d\",i);
printf(\"%s\",itoa(i));//把i转换为字符串并输出

getchar();
return 0;
}





time.h是包含与时间相关的函数

函数体有:

time_t time(time_t *); 获取当前时间为一个长整数
char * ctime(const time_t *);将时间结构time_t转换为字符串
char * asctime(const struct tm *);将tm结构转换为字符串
struct tm * gmtime(const time_t *);将时间结构转换为tm结构 GMT
struct tm * localtime(const time_t *);将时间结构转换为tm结构 LT
time_t mktime(struct tm *);将tm结构转换为time_t结构
double difftime(time_t, time_t);将前一个减去后一个的差额
clock_t clock(void);返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick)数

tm结构:
struct tm {
int tm_sec; /* seconds after the minute - [0,59] * /
int tm_min; /* minutes after the hour - [0,59] * /
int tm_hour; /* hours since midnight - [0,23] * /
int tm_mday; /* day of the month - [1,31] * /
int tm_mon; /* months since January - [0,11] * /
int tm_year; /* years since 1900 * /
int tm_wday; /* days since Sunday - [0,6] * /
int tm_yday; /* days since January 1 - [0,365] * /
int tm_isdst; /* daylight savings time flag * /
};


例如:

程序代码:
#include <time.h>

main()
{
time_t now;
{
struct tm *l_time;
char string1[20];
time(&now);
l_time = localtime(&now);
strftime(string1, sizeof string1, \"%d/%b/%y\n\", l_time);
printf(\"The current date is %s\", string1);
}
}//结果为The current date is 12/Oct/06



----------------解决方案--------------------------------------------------------
太感谢了!~~
----------------解决方案--------------------------------------------------------
谢谢

----------------解决方案--------------------------------------------------------
  相关解决方案