关于 gcc 和 vc++ 的问题
经常碰到的问题是,一个以.c文件结尾的文件,在gcc上编译一点错误没有,结果正确。而在vc++上编译时就老出错,请问这是为什么啊?是我代码写的不规范造成的吗?
搜索更多相关的解决方案:
gcc
----------------解决方案--------------------------------------------------------
比如
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char pathname[10];
printf("input the file name: ");
scanf("%s",pathname);
strcat(pathname,".in");
FILE *fp;
fp = fopen( pathname , "r+" );
if( fp == NULL )
{
printf(" can not open file !!\n");
return 0;
}
printf("opened!\n\n\n");
fclose(fp);
printf("closed!\n\n\n");
return 0;
}
在gcc上就能正常的编译,结果如所料一样。
而在vc++上就会出现这样的错误提示:
e:\source\exp1.c(19) : error C2275: 'FILE' : illegal use of this type as an expression
e:\program files\microsoft visual studio\vc98\include\stdio.h(156) : see declaration of 'FILE'
e:\source\exp1.c(19) : error C2065: 'fp' : undeclared identifier
有没有告诉我为什么会这样?怎么解决?
----------------解决方案--------------------------------------------------------
是VC6??把文件指针的申明提到程序的前面去.
----------------解决方案--------------------------------------------------------
原来是这样,谢谢
是编译器的问题,是吧?
----------------解决方案--------------------------------------------------------
对,以前的标准要求变量申明必须在一个程序的开始,而C99修改为在首次使用之前就可以.
----------------解决方案--------------------------------------------------------