首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请问怎么修改这个warning

2012-03-19 
请教如何修改这个warningtime_t t time(NULL)printf(%s,ctime(&t))经PCLINT检查,printf(%s,ctime(

请教如何修改这个warning
time_t t = time(NULL);
printf("%s",ctime(&t));

经PCLINT检查,printf("%s",ctime(&t))这行代码,出现下面的WARNING,该如何修改?
Issue 559: (Warning -- Size of argument no. 2 inconsistent with format)


[解决办法]

C/C++ code
#include <stdio.h>#include <time.h>int main (){  time_t t=time(NULL);  int n;  n=printf ( "%s", ctime (&t));  printf("The length is %d.",n);  return 0;}
[解决办法]
探讨
time_t t = time(NULL);
printf("%s",ctime(&amp;t));

经PCLINT检查,printf("%s",ctime(&amp;t))这行代码,出现下面的WARNING,该如何修改?
Issue 559: (Warning -- Size of argument no. 2 inconsistent with format)

[解决办法]
//returns a pointer to the character string result. If time represents a date before midnight, January 1, 1970, UTC, the function returns NULL

time_t t = time(NULL);
char *s=ctime(&t);
if (NULL!=s) printf("%s",s);
else printf("NULL");

热点排行