请教如何修改这个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;}
[解决办法]
[解决办法]
//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");