关于C语言文件读取fopen函数的问题

Tony_cheer 2016-11-28 02:30:41
刚入门学习C语言,用VS2012平台,使用fopen函数时报错:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
FILE * fp;
if (fopen_s(&fp,"C:\\Users\\Administrator\\Desktop\\EGM96","r")!=0)
{
printf("The file open error!\n");
exit(0);
}
int a;
a=fclose(fp);
return 0;
}


设断点逐步运行时,出现报错:
>c:\users\administrator\desktop\test\test\test.c(14): error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
int main(void)
{
FILE * fp;
/*if (fopen_s(&fp,"C:\\Users\\Administrator\\Desktop\\EGM96","r")!=0)
{
printf("The file open error!\n");
exit(0);
}*/
int a;
//a=fclose(fp);
return 0;
}

这样就能运行了,求解答,谢谢!
另外,VS配置了opencv 不知是不是受这个影响
...全文
197 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunsky_yi 2019-03-27
  • 打赏
  • 举报
回复
学习受教了,不过每天进步还是太少
paschen 2016-11-28
  • 打赏
  • 举报
回复
引用 2 楼 Tony_cheer 的回复:
问题解决谢谢! 可是我记得新的C99?是可以在使用变量时再定义呀,为何这里不行呢?
VS不支持C99
小灸舞 版主 2016-11-28
  • 打赏
  • 举报
回复
C99真不支持

http://msdn.microsoft.com/en-us/library/02y9a5ye.aspx

Microsoft C conforms to the standard for the C language as set forth in the 9899:1990 edition of the ANSI C standard.
ipqtjmqj 2016-11-28
  • 打赏
  • 举报
回复
Microsoft Visual C++ Partial[13] Visual C++ 2012 and earlier did not support C99.[28][29][30] Visual C++ 2013 implements a limited subset of C99 required to compile popular open-source projects.[31][32] Visual C++ 2015 implements the C99 standard library, with the exception of any library features that depend on compiler features not yet supported by the compiler (for example, <tgmath.h> is not implemented).[13]
ipqtjmqj 2016-11-28
  • 打赏
  • 举报
回复
引用 3 楼 Tony_cheer 的回复:
@ipqtjmqj
我查了下,好像也不是完全支持C99,参考
ipqtjmqj 2016-11-28
  • 打赏
  • 举报
回复
引用 3 楼 Tony_cheer 的回复:
@ipqtjmqj
估计得设置一下编译器吧
Tony_cheer 2016-11-28
  • 打赏
  • 举报
回复
@ipqtjmqj
Tony_cheer 2016-11-28
  • 打赏
  • 举报
回复
问题解决谢谢! 可是我记得新的C99?是可以在使用变量时再定义呀,为何这里不行呢?
ipqtjmqj 2016-11-28
  • 打赏
  • 举报
回复
变量定义要放最前面

70,020

社区成员

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

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