FILE ×p这是什么错误?

winterdebin 2008-07-01 09:26:07
Error: Improper use of a typedef symbol in function main
#include <string.h>
main()
{
char FileName[50],FilePath[100]={"c:\\"};
printf("Input the file name:\n");
gets(FileName);
strcat(FilePath,FileName);
FILE *p;
if(p=fopen(FilePath,"wt")==NULL)
printf("Error\n");
else
printf("OK\n");
}
...全文
151 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
FLxyzsby 2008-07-01
  • 打赏
  • 举报
回复
C语言可不象C++
要求必须把所有的声明写在最前面
BMCRNET 2008-07-01
  • 打赏
  • 举报
回复
C语言规则问题

函数体内的所有声明必须放在最前面
e_sharp 2008-07-01
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 winterdebin 的回复:]
#include <stdio.h>
#include <string.h>
main()
{
FILE *fp;
char FileName[50],FilePath[100]={"c:\\"};
printf("Input the file name:\n");
gets(FileName);
strcat(FilePath,FileName);
if(fp=fopen(FilePath,"wt")==NULL)
printf("Error\n");
else
printf("OK\n");
}
这样就能用了,但为什么一定要把FILE *fp;放在最前面来声明?
[/Quote]

C语言的语法就是这样要求的,声明必须在前;c++可以任意位置声明
yyyapple 2008-07-01
  • 打赏
  • 举报
回复
C编译器潜规则
长尾巴的悟空 2008-07-01
  • 打赏
  • 举报
回复
感觉没有影响吧?
winterdebin 2008-07-01
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <string.h>
main()
{
FILE *fp;
char FileName[50],FilePath[100]={"c:\\"};
printf("Input the file name:\n");
gets(FileName);
strcat(FilePath,FileName);
if(fp=fopen(FilePath,"wt")==NULL)
printf("Error\n");
else
printf("OK\n");
}
这样就能用了,但为什么一定要把FILE *fp;放在最前面来声明?
winterdebin 2008-07-01
  • 打赏
  • 举报
回复
恩,你的对了
jy02684358 2008-07-01
  • 打赏
  • 举报
回复
编译器比较老吧,把定义放到最上面。另外if((p = fopen(FilePath,"wt"))==NULL) 这句这样写好些吧加个括号好像赋值运算的级别比判断还低。
Oversense 2008-07-01
  • 打赏
  • 举报
回复
#include <stdio.h>
king_water 2008-07-01
  • 打赏
  • 举报
回复
FILE *p;
这么写没错, FILE不是指针
报什么错
xkyx_cn 2008-07-01
  • 打赏
  • 举报
回复
不是啊,FILE* p;是正确的

Error: Improper use of a typedef symbol in function main
这个错误没看出来

[Quote=引用 1 楼 artman 的回复:]
FILE p;

FILE 已经是指针!
[/Quote]
ForestDB 2008-07-01
  • 打赏
  • 举报
回复
#include <stdio.h>

另外你用的是C,把声明挪到最前面去。
artman 2008-07-01
  • 打赏
  • 举报
回复
FILE p;

FILE 已经是指针!

69,371

社区成员

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

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