c语言中函数met c语言中函数没有参数

c语言时间处理函数C语言c语言中函数met的标准库函数包括一系列日期和时间处理函数 , 它们都在头文件中说明 。
在头文件中定义c语言中函数met了三种类型:time_t , struct tm和clock_t 。
下面列出了这些函数 。
time_t time(time_t *timer);
double difftime(time_t time1,time_t time2);
struct tm *gmtime(const time_t *timer);
struct tm *localtime(const time_t *timer);
char *asctime(const struct tm *timeptr);
char *ctime(const time_t *timer);
size_t strftime(char *s,size_t maxsize,const char *format,const struct tm *timeptr);
time_t mktime(struct tm *timeptr);
clock_t clock(void);
【具体应用举例】
asctime(将时间和日期以字符串格式表示)
相关函数
time , ctime,gmtime,localtime
表头文件
#i nclude
定义函数
char * asctime(const struct tm * timeptr);
函数说明
asctime()将参数timeptr所指的tm结构中的信息转换成真实世界所使用的时间日期表示方法 , 然后将结果以字符串形态返回 。
此函数已经由时区转换成当地时间 , 字符串格式为:"Wed Jun 30 21:49:08 1993\n"
返回值
若再调用相关的时间日期函数,此字符串可能会被破坏 。此函数与ctime不同处在于传入的参数是不同的结构 。
附加说明
返回一字符串表示目前当地的时间日期 。
范例
#i nclude
main()
{
time_t timep;
time (timep);
printf("%s",asctime(gmtime(timep)));
}
执行
Sat Oct 28 02:10:06 2000
ctime(将时间和日期以字符串格式表示)
相关函数
time , asctime , gmtime,localtime
表头文件
#i nclude
定义函数
char *ctime(const time_t *timep);
函数说明
ctime ()将参数timep所指的time_t结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回 。
此函数已经由时区转换成当地时间,字符串格式为"Wed Jun 30 21 :49 :08 1993\n" 。若再调用相关的时间日期函数,此字符串可能会被破坏 。
返回值
返回一字符串表示目前当地的时间日期 。
范例
#i nclude
main()
{
time_t timep;
time (timep);
printf("%s",ctime(timep));
}
执行
Sat Oct 28 10 : 12 : 05 2000
gettimeofday(取得目前的时间)
相关函数
time,ctime,ftime , settimeofday
表头文件
#i nclude
#i nclude
定义函数
int gettimeofday ( struct timeval * tv , struct timezone * tz )
函数说明
gettimeofday()会把目前的时间有tv所指的结构返回,当地时区的信息则放到tz所指的结构中 。
timeval结构定义为:
struct timeval{
long tv_sec; /*秒*/
long tv_usec; /*微秒*/
};
timezone 结构定义为:
struct timezone{
int tz_minuteswest; /*和Greenwich 时间差了多少分钟*/
int tz_dsttime; /*日光节约时间的状态*/
};
上述两个结构都定义在/usr/include/sys/time.h 。tz_dsttime 所代表的状态如下
DST_NONE /*不使用*/
DST_USA /*美国*/
DST_AUST /*澳洲*/
DST_WET /*西欧*/
DST_MET /*中欧*/
DST_EET /*东欧*/
DST_CAN /*加拿大*/
DST_GB /*大不列颠*/
DST_RUM /*罗马尼亚*/
DST_TUR /*土耳其*/
DST_AUSTALT /*澳洲(1986年以后)*/
返回值
成功则返回0,失败返回-1,错误代码存于errno 。附加说明EFAULT指针tv和tz所指的内存空间超出存取权限 。
范例
#i nclude
#i nclude
main(){
struct timeval tv;
struct timezone tz;
gettimeofday (tv , tz);
printf("tv_sec; %d\n", tv,.tv_sec) ;
printf("tv_usec; %d\n",tv.tv_usec);
printf("tz_minuteswest; %d\n", tz.tz_minuteswest);
printf("tz_dsttime, %d\n",tz.tz_dsttime);
}
执行
tv_sec: 974857339
tv_usec:136996
tz_minuteswest:-540
tz_dsttime:0
gmtime(取得目前时间和日期)
相关函数
time,asctime,ctime,localtime
表头文件
#i nclude
定义函数
struct tm*gmtime(const time_t*timep);
函数说明
gmtime()将参数timep 所指的time_t 结构中的信息转换成真实世界所使用的时间日期表示方法 , 然后将结果由结构tm返回 。
结构tm的定义为
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
int tm_sec 代表目前秒数 , 正常范围为0-59,但允许至61秒
int tm_min 代表目前分数,范围0-59
int tm_hour 从午夜算起的时数,范围为0-23
int tm_mday 目前月份的日数,范围01-31
int tm_mon 代表目前月份,从一月算起,范围从0-11
int tm_year 从1900 年算起至今的年数
int tm_wday 一星期的日数 , 从星期一算起,范围为0-6
int tm_yday 从今年1月1日算起至今的天数 , 范围为0-365
int tm_isdst 日光节约时间的旗标
此函数返回的时间日期未经时区转换,而是UTC时间 。
返回值
返回结构tm代表目前UTC 时间
范例
#i nclude
main(){
char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
time_t timep;
struct tm *p;
time(timep);
p=gmtime(timep);
printf("%d%d%d",(1900 p-tm_year), (1 p-tm_mon),p-tm_mday);
printf("%s%d;%d;%d\n", wday[p-tm_wday], p-tm_hour, p-tm_min, p-tm_sec);
}
执行
2000/10/28 Sat 8:15:38
localtime(取得当地目前时间和日期)
相关函数
time, asctime, ctime, gmtime
表头文件
#i nclude
定义函数
struct tm *localtime(const time_t * timep);
函数说明
localtime()将参数timep所指的time_t结构中的信息转换成真实世界所使用的时间日期表示方法 , 然后将结果由结构tm返回 。
结构tm的定义请参考gmtime() 。此函
数返回的时间日期已经转换成当地时区 。
返回值
返回结构tm代表目前的当地时间 。
范例
#i nclude
main(){
char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
time_t timep;
struct tm *p;
time(timep);
p=localtime(timep); /*取得当地时间*/
printf ("%d%d%d ", (1900 p-tm_year),( l p-tm_mon), p-tm_mday);
printf("%s%d:%d:%d\n", wday[p-tm_wday],p-tm_hour, p-tm_min, p-tm_sec);
}
执行
2000/10/28 Sat 11:12:22
mktime(将时间结构数据转换成经过的秒数)
相关函数
time,asctime , gmtime,localtime
表头文件
【c语言中函数met c语言中函数没有参数】#i nclude
定义函数
time_t mktime(strcut tm * timeptr);
函数说明
mktime()用来将参数timeptr所指的tm结构数据转换成从公元1970年1月1日0时0分0 秒算起至今的UTC时间所经过的秒数 。
返回值
返回经过的秒数 。
范例
/* 用time()取得时间(秒数) , 利用localtime()
转换成struct tm 再利用mktine()将struct tm转换成原来的秒数*/
#i nclude
main()
{
time_t timep;
strcut tm *p;
time(timep);
printf("time() : %d \n",timep);
p=localtime(timep);
timep = mktime(p);
printf("time()-localtime()-mktime():%d\n",timep);
}
执行
time():974943297
time()-localtime()-mktime():974943297
settimeofday(设置目前时间)
相关函数
time,ctime , ftime,gettimeofday
表头文件
#i nclude
#i nclude
定义函数
int settimeofday ( const struct timeval *tv,const struct timezone *tz);
函数说明
settimeofday()会把目前时间设成由tv所指的结构信息,当地时区信息则设成tz所指的结构 。详细的说明请参考gettimeofday() 。
注意,只有root权限才能使用此函数修改时间 。
返回值
成功则返回0,失败返回-1 , 错误代码存于errno 。
错误代码
EPERM 并非由root权限调用settimeofday() , 权限不够 。
EINVAL 时区或某个数据是不正确的,无法正确设置时间 。
time(取得目前的时间)
相关函数
ctime,ftime,gettimeofday
表头文件
#i nclude
定义函数
time_t time(time_t *t);
函数说明
此函数会返回从公元1970年1月1日的UTC时间从0时0分0秒算起到现在所经过的秒数 。如果t 并非空指针的话,
此函数也会将返回值存到t指针所指的内存 。
返回值
成功则返回秒数,失败则返回((time_t)-1)值,错误原因存于errno中 。
范例
#i nclude
mian()
{
int seconds= time((time_t*)NULL);
printf("%d\n",seconds);
}
Date and Time Functions: time.h
The header time.h declares types and functions for manipulating date and time. Some functions process local time,
which may differ from calendar time, for example because of time zone. clock_t and time_t are arithmetic types
representing times, and struct tm holds the components
of a calendar time:
int tm_sec;seconds after the minute (0,61)
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 Saving Time flag
tm_isdst is positive if Daylight Saving Time is in effect, zero if not, and negative if the information is not available.
clock_t clock(void)
clock returns the processor time used by the program since the beginning of execution, or -1 if unavailable.
clock()/CLK_PER_SEC is a time in
seconds.
time_t time(time_t *tp)
time returns the current calendar time or -1 if the time is not available. If tp is not NULL,
the return value is also assigned to *tp.
double difftime(time_t time2, time_t time1)
difftime returns time2-time1 expressed in seconds.
time_t mktime(struct tm *tp)
mktime converts the local time in the structure *tp into calendar time in the same representation used by time.
The components will have values
in the ranges shown. mktime returns the calendar time or -1 if it cannot be represented.
The next four functions return pointers to static objects that may be overwritten by other calls.
char *asctime(const struct tm *tp)
asctime*tp into a string of the form
Sun Jan3 15:14:13 1988\n\0
char *ctime(const time_t *tp)
ctime converts the calendar time *tp to local time; it is equivalent to
asctime(localtime(tp))
struct tm *gmtime(const time_t *tp)
gmtime converts the calendar time *tp into Coordinated Universal Time (UTC). It returns NULL if UTC is not available.
The name gmtime has historical significance.
struct tm *localtime(const time_t *tp)
localtime converts the calendar time *tp into local time.
size_t strftime(char *s, size_t smax, const char *fmt, const struct tm *tp)
strftime formats date and time information from *tp into s according to fmt, which is analogous to a printf format.
Ordinary characters (including the terminating '\0') are copied into s. Each %c is replaced as described below,
using values appropriate for the local environment.
No more than smax characters are placed into s. strftime returns the number of characters, excluding the '\0',
or zero if more than smax characters were produced.
%a abbreviated weekday name.
%A full weekday name.
%b abbreviated month name.
%B full month name.
%c local date and time representation.
%d day of the month (01-31).
%H hour (24-hour clock) (00-23).
%I hour (12-hour clock) (01-12).
%j day of the year (001-366).
%m month (01-12).
%M minute (00-59).
%p local equivalent of AM or PM.
%S second (00-61).
\u week number of the year (Sunday as 1st day of week) (00-53).
%w weekday (0-6, Sunday is 0).
%W week number of the year (Monday as 1st day of week) (00-53).
%x local date representation.
%X local time representation.
%y year without century (00-99).
%Y year with century.
%Z time zone name, if any.
%%%
C语言中的math函数一些数学计算的公式的具体实现是放在math.h里,具体有c语言中函数met:
double sin (double x);x的正弦值
double cos (double x);x的余弦值
double tan (double x);x的正切值
double asin (double x);结果介于[-PI/2, PI/2]c语言中函数met , x值域为[-1,1]
double acos (double x);结果介于[0, PI],x值域为[-1,1]
double atan (double x);反正切(主值), 结果介于[-PI/2, PI/2]
double atan2 (double y, double x);反正切(整圆值), 结果介于[-PI, PI]
double sinh (double x);x的双曲正弦值
double cosh (double x);x的双曲余弦值
double tanh (double x);x的双曲正切值
double exp (double x);幂函数e^x
double pow (double x, double y);x^yc语言中函数met , 如果x=0且y=0,或者x0且y不是整型数c语言中函数met,将产生定义域错误
double sqrt (double x);x的平方根,其中x=0
double log (double x);以e为底的对数,自然对数 , x0
double log10 (double x);以10为底的对数,x0
double ceil (double x);取上整
double floor (double x);取下整
double fabs (double x);x的绝对值
double frexp (double x, int *exp);标准化浮点数, x = f * 2^exp, 已知x求f, exp ( x介于[0.5, 1] )并返回f值
double ldexp (double x, int exp);与frexp相反, 已知x, exp求x*2^exp
double modf (double x, double *ip);将参数的整数部分通过指针回传, 返回小数部分,整数部分保存在*ip中
double fmod (double x, double y);返回两参数相除x/y的余数,符号与x相同 。如果y为0 , 则结果与具体的额实现有关
c语言中math头文件中的函数有哪些数学函数库,一些数学计算c语言中函数met的公式的具体实现是放在math.h里,具体有:
1 三角函数
double sin (double);
double cos (double);
double tan (double);
2 反三角函数
double asin (double); 结果介于[-PI/2, PI/2]
double acos (double); 结果介于[0, PI]
double atan (double); 反正切(主值), 结果介于[-PI/2, PI/2]
double atan2 (double, double); 反正切(整圆值), 结果介于[-PI/2, PI/2]
3 双曲三角函数
double sinh (double);
double cosh (double);
double tanh (double);
4 指数与对数
double exp (double);
double sqrt (double);
double log (double); 以e为底的对数
double log10 (double);
double pow(double x, double y)//计算以x为底数的y次幂
5 取整
double ceil (double); 取上整
double floor (double); 取下整
6 绝对值
double fabs (double);
double cabs(struct complex znum) //求复数的绝对值
7 标准化浮点数
double frexp (double f, int *p); 标准化浮点数, f = x * 2^p, 已知f求x, p ( x介于[0.5, 1] )
double ldexp (double x, int p); 与frexp相反, 已知x, p求f
8 取整与取余
double modf (double, double*); 将参数的整数部分通过指针回传, 返回小数部分
double fmod (double, double); 返回两参数相除的余数
9其他
double hypot(double x, double y);//已知直角三角形两个直角边长度c语言中函数met,求斜边长度
double ldexp(double x, int exponent);//计算x*(2的exponent次幂)
double poly(double x, int degree, double coeffs [] )//计算多项式
nt matherr(struct exception *e)//数学错误计算处理程序
source: 《CCCode Capsules》
C语言中获取时间的方法是什么C语言的标准库
函数包括一系列日期和时间处理函数,它们都在头文件中说明 。下面列出了这些函数 。在头文件中定义了三种类型:time_t,struct tm和clock_t 。
在中说明的C语言时间函数
time_t time(time_t *timer);
double difftime(time_t time1,time_t time2);
struct tm *gmtime(const time_t *timer);
struct tm *localtime(const time_t *timer);
char *asctime(const struct tm *timeptr);
char *ctime(const time_t *timer);
size_t strftime(char *s,size_t maxsize,const char *format,const struct tm *timeptr);
time_t mktime(struct tm *timeptr);
clock_t clock(void);
下面是我从网上收集到的时间函数集
asctime(将时间和日期以字符串格式表示)
相关函数
time,ctime,gmtime , localtime
表头文件
#i nclude
定义函数
char * asctime(const struct tm * timeptr);
函数说明
asctime()将参数timeptr所指的tm结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回 。此函数已经由时区转换成当地时间 , 字符串格式为:"Wed Jun 30 21:49:08 1993\n"
返回值
若再调用相关的时间日期函数,此字符串可能会被破坏 。此函数与ctime不同处在于传入的参数是不同的结构 。
附加说明
返回一字符串表示目前当地的时间日期 。
范例
#i nclude
main()
{
time_t timep;
time (timep);
printf("%s",asctime(gmtime(timep)));
}
执行
Sat Oct 28 02:10:06 2000
ctime(将时间和日期以字符串格式表示)
相关函数
time , asctime,gmtime , localtime
表头文件
#i nclude
定义函数
char *ctime(const time_t *timep);
函数说明
ctime ()将参数timep所指的time_t结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回 。此函数已经由时区转换成当地时间,字符串格式为"Wed Jun 30 21 :49 :08 1993\n" 。若再调用相关的时间日期函数,此字符串可能会被破坏 。
返回值
返回一字符串表示目前当地的时间日期 。
范例
#i nclude
main()
{
time_t timep;
time (timep);
printf("%s",ctime(timep));
}
执行
Sat Oct 28 10 : 12 : 05 2000
gettimeofday(取得目前的时间)
相关函数
time,ctime,ftime,settimeofday
表头文件
#i nclude
#i nclude
定义函数
int gettimeofday ( struct timeval * tv , struct timezone * tz )
函数说明
gettimeofday()会把目前的时间有tv所指的结构返回,当地时区的信息则放到tz所指的结构中 。
timeval结构定义为:
struct timeval{
long tv_sec; /*秒*/
long tv_usec; /*微秒*/
};
timezone 结构定义为:
struct timezone{
int tz_minuteswest; /*和Greenwich 时间差了多少分钟*/
int tz_dsttime; /*日光节约时间的状态*/
};
上述两个结构都定义在/usr/include/sys/time.h 。tz_dsttime 所代表的状态如下
DST_NONE /*不使用*/
DST_USA /*美国*/
DST_AUST /*澳洲*/
DST_WET /*西欧*/
DST_MET /*中欧*/
DST_EET /*东欧*/
DST_CAN /*加拿大*/
DST_GB /*大不列颠*/
DST_RUM /*罗马尼亚*/
DST_TUR /*土耳其*/
DST_AUSTALT /*澳洲(1986年以后)*/
返回值
成功则返回0,失败返回-1,错误代码存于errno 。附加说明EFAULT指针tv和tz所指的内存空间超出存取权限 。
范例
#i nclude
#i nclude
main(){
struct timeval tv;
struct timezone tz;
gettimeofday (tv , tz);
printf("tv_sec; %d\n", tv,.tv_sec) ;
printf("tv_usec; %d\n",tv.tv_usec);
printf("tz_minuteswest; %d\n", tz.tz_minuteswest);
printf("tz_dsttime, %d\n",tz.tz_dsttime);
}
执行
tv_sec: 974857339
tv_usec:136996
tz_minuteswest:-540
tz_dsttime:0
gmtime(取得目前时间和日期)
相关函数
time,asctime,ctime,localtime
表头文件
#i nclude
定义函数
struct tm*gmtime(const time_t*timep);
函数说明
gmtime()将参数timep 所指的time_t 结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果由结构tm返回 。
结构tm的定义为
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
int tm_sec 代表目前秒数,正常范围为0-59,但允许至61秒
int tm_min 代表目前分数,范围0-59
int tm_hour 从午夜算起的时数,范围为0-23
int tm_mday 目前月份的日数 , 范围01-31
int tm_mon 代表目前月份 , 从一月算起,范围从0-11
int tm_year 从1900 年算起至今的年数
int tm_wday 一星期的日数,从星期一算起,范围为0-6
int tm_yday 从今年1月1日算起至今的天数,范围为0-365
int tm_isdst 日光节约时间的旗标
此函数返回的时间日期未经时区转换,而是UTC时间 。
返回值
返回结构tm代表目前UTC 时间
范例
#i nclude
main(){
char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
time_t timep;
struct tm *p;
time(timep);
p=gmtime(timep);
printf("%d%d%d",(1900 p-tm_year), (1 p-tm_mon),p-tm_mday);
printf("%s%d;%d;%d\n", wday[p-tm_wday], p-tm_hour, p-tm_min, p-tm_sec);
}
执行
2000/10/28 Sat 8:15:38
localtime(取得当地目前时间和日期)
相关函数
time, asctime, ctime, gmtime
表头文件
#i nclude
定义函数
struct tm *localtime(const time_t * timep);
函数说明
localtime()将参数timep所指的time_t结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果由结构tm返回 。结构tm的定义请参考gmtime() 。此函数返回的时间日期已经转换成当地时区 。
返回值
返回结构tm代表目前的当地时间 。
范例
#i nclude
main(){
char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
time_t timep;
struct tm *p;
time(timep);
p=localtime(timep); /*取得当地时间*/
printf ("%d%d%d ", (1900 p-tm_year),( l p-tm_mon), p-tm_mday);
printf("%s%d:%d:%d\n", wday[p-tm_wday],p-tm_hour, p-tm_min, p-tm_sec);
}
执行
2000/10/28 Sat 11:12:22
mktime(将时间结构数据转换成经过的秒数)
相关函数
time , asctime,gmtime,localtime
表头文件
#i nclude
定义函数
time_t mktime(strcut tm * timeptr);
函数说明
mktime()用来将参数timeptr所指的tm结构数据转换成从公元1970年1月1日0时0分0 秒算起至今的UTC时间所经过的秒数 。
返回值
返回经过的秒数 。
范例
/* 用time()取得时间(秒数),利用localtime()
转换成struct tm 再利用mktine()将struct tm转换成原来的秒数*/
#i nclude
main()
{
time_t timep;
strcut tm *p;
time(timep);
printf("time() : %d \n",timep);
p=localtime(timep);
timep = mktime(p);
printf("time()-localtime()-mktime():%d\n",timep);
}
执行
time():974943297
time()-localtime()-mktime():974943297
settimeofday(设置目前时间)
相关函数
time,ctime,ftime,gettimeofday
表头文件
#i nclude
#i nclude
定义函数
int settimeofday ( const struct timeval *tv,const struct timezone *tz);
函数说明
settimeofday()会把目前时间设成由tv所指的结构信息,当地时区信息则设成tz所指的结构 。详细的说明请参考gettimeofday() 。注意,只有root权限才能使用此函数修改时间 。
返回值
成功则返回0,失败返回-1 , 错误代码存于errno 。
错误代码
EPERM 并非由root权限调用settimeofday(),权限不够 。
EINVAL 时区或某个数据是不正确的 , 无法正确设置时间 。
c语言中函数memset()是什么意思?什么功能memset()的函数,它可以一字节一字节地把整个数组设置为一个指定的值 。memset()函数在mem.h头文件中声明 , 它把数组的起始地址作为其第一个参数,第二个参数是设置数组每个字节的值,第三个参数是数组的长度(字节数,不是元素个数) 。其函数原型为:
void *memset(void* , int,unsigned);
其中void*表示地址
memset()的第一个实参是数组名,数组名作参数即数组作参数,它仅仅只是一个数组的起始地址而已 。
实现第一个memset()函数调用的内存布局见图7-3 。在函数memset()栈区,从返回地址往上依次为第1,2,3个参数 。第1个参数中的内容是main()函数中定义的数组ia1的起始地址 。第2个参数是给数组设置的值(0),第3个参数是数组的长度(50*2) 。函数返回时,main()函数的数组中内容全置为0 。
c语言中函数met的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于c语言中函数没有参数、c语言中函数met的信息别忘了在本站进行查找喔 。

    推荐阅读