【发布时间】:2012-11-08 19:32:49
【问题描述】:
以下代码应该可以工作(这是 stackoveflow 中公认的答案),但不知何故我收到了两个警告,因此我收到了分段错误。怎么了?
time_t timer;
char buffer[25];
struct tm* tm_info;
time(&timer);
tm_info = localtime(&timer);
strftime(buffer, 25, "%Y:%m:%d%H:%M:%S", tm_info);
bead.c:61: 警告:赋值使指针从整数而不进行强制转换 bead.c:63: 警告:内置函数 âstrftimeâ
的隐式声明不兼容line 61 is tm_info = localtime(&timer);
and line 63 is strftime(buffer, 25, "%Y:%m:%d%H:%M:%S", tm_info);
【问题讨论】:
-
哪个编译器?您的示例实际上与文档中的示例相同:cplusplus.com/reference/clibrary/ctime/strftime
标签: c segmentation-fault