关于struct tm的使用问题,在线等

asyuae 2012-11-01 05:11:31

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<limits.h>
#include<stdarg.h>
#include<assert.h>
#include<time.h>

void main(){

int *a=(int*)calloc(4,2);
system("color 4E");
struct tm *k;
// printf("%d",d.tm_sec);
exit(0);
}

上面的就有错误:error C2143: syntax error : missing ';' before 'type'
注销掉system("color 4E");这句就没有错误


#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<limits.h>
#include<stdarg.h>
#include<assert.h>
#include<time.h>

void main(){

int *a=(int*)calloc(4,2);
// system("color 4E");
struct tm *k;
// printf("%d",d.tm_sec);
exit(0);
}


这是怎么了??????
...全文
5378 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
asyuae 2012-11-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

找到原因了,是因为C语言要求变量在前面声明:
C/C++ code

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<limits.h>
#include<stdarg.h>
#include<assert.h>
#include<time.h>

int main()
{

int* a = (int*……
[/Quote]
呜呜呜,一直用c++,突然转回来就懵了。。。。。。。
谢谢了
图灵狗 2012-11-01
  • 打赏
  • 举报
回复
找到原因了,是因为C语言要求变量在前面声明:

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<limits.h>
#include<stdarg.h>
#include<assert.h>
#include<time.h>

int main()
{

int* a = (int*)calloc(4, 2);
struct tm* k;

system("color 4E");
time_t t = time(NULL);
k = localtime(&t);
printf("%d\n", k->tm_sec);

return 0;
}

nice_cxf 2012-11-01
  • 打赏
  • 举报
回复
C89把?
定义必须在开始部分

int *a=(int*)calloc(4,2);
struct tm *k;
system("color 4E");
这样应该就可以了
mujiok2003 2012-11-01
  • 打赏
  • 举报
回复
试试这个在线编译器http://codepad.org
mujiok2003 2012-11-01
  • 打赏
  • 举报
回复

#include <iostream>
#include <iomanip>
#include <ctime>

int main()
{
std::time_t t = std::time(0);
std::tm* p = std::localtime(&t);
printf("%d",p->tm_sec);
return 0;
}
图灵狗 2012-11-01
  • 打赏
  • 举报
回复
GCC下编译没有问题啊,你是什么编译器?还是抄上来的代码不对?

69,374

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧