关于typedef struct的报错的问题

小耸 2009-08-17 03:22:32
我用VC++6.0
为什么我的程序中一插入typedef struct就报错
如:
typedef struct BMP_file
{
unsigned int bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int Reserved2;
unsigned long bfOffset;
}bitmapfile;

报错为
d:\My Documents\my_c\bmp_xs\1.c(18) : error C2143: syntax error : missing ';' before '<class-head>'
d:\My Documents\my_c\bmp_xs\1.c(20) : error C2143: syntax error : missing ';' before 'type'
d:\My Documents\my_c\bmp_xs\1.c(21) : error C2143: syntax error : missing ';' before 'type'
d:\My Documents\my_c\bmp_xs\1.c(22) : error C2143: syntax error : missing ';' before 'type'
d:\My Documents\my_c\bmp_xs\1.c(23) : error C2143: syntax error : missing ';' before 'type'
d:\My Documents\my_c\bmp_xs\1.c(26) : error C2059: syntax error : '}'


谢谢大家。。。
...全文
703 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
iceway 2009-08-17
  • 打赏
  • 举报
回复
如果你非要放到函数内部, 那就放到函数开始处

#include <stdio.h>
#include <stdlib.h>



void main()
{
typedef int WIDTH;
int i=0;
int j=0;
unsigned char image_in[320][200];
FILE *fp;
char filename[20];
typedef struct BMP_file
{
unsigned int bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int Reserved2;
unsigned long bfOffset;
}bitmapfile;

printf("ÇëÊäÈëÎļþµÄÃû³Æ£º\n");
scanf("%s",filename);
fp=fopen(filename,"r");
if(fp==NULL)
{
printf("Open the file is fail!\n");
exit(0);
};

}
小耸 2009-08-17
  • 打赏
  • 举报
回复
谢谢楼上了,我是菜鸟呵呵。。
gisgamer 2009-08-17
  • 打赏
  • 举报
回复
struct 定义在main()里????
iceway 2009-08-17
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>

typedef struct BMP_file
{
unsigned int bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int Reserved2;
unsigned long bfOffset;
}bitmapfile;

void main()
{
int i=0;
int j=0;
unsigned char image_in[320][200];
FILE *fp;
char filename[20];
printf("ÇëÊäÈëÎļþµÄÃû³Æ£º\n");
scanf("%s",filename);
fp=fopen(filename,"r");
if(fp==NULL)
{
printf("Open the file is fail!\n");
exit(0);
}

}

这样, 晕了, 你怎么把typedef放到函数体内部了?
小耸 2009-08-17
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 iceway 的回复:]
晕, 楼上的说VC6太老了, 就算再老 也不至于连个基本的结构体定义都会出错吧, 肯定还是代码问题

楼主, 把你的源代码帖出来吧...
[/Quote]

在8楼
iceway 2009-08-17
  • 打赏
  • 举报
回复
晕, 楼上的说VC6太老了, 就算再老 也不至于连个基本的结构体定义都会出错吧, 肯定还是代码问题

楼主, 把你的源代码帖出来吧...
wanjingwei 2009-08-17
  • 打赏
  • 举报
回复
VC6编译的也没错呀,你是不是其他地方有问题
小耸 2009-08-17
  • 打赏
  • 举报
回复
这是代码,我还没写完。写开头一点。
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i=0;
int j=0;
unsigned char image_in[320][200];
FILE *fp;
char filename[20];
printf("请输入文件的名称:\n");
scanf("%s",filename);
fp=fopen(filename,"r");
if(fp==NULL)
{
printf("Open the file is fail!\n");
exit(0);
}
typedef struct BMP_file
{
unsigned int bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int Reserved2;
unsigned long bfOffset;
}bitmapfile;
}
yshuise 2009-08-17
  • 打赏
  • 举报
回复
vc2003测试没有错。vc6太老了。
换一个编译器试试。
iceway 2009-08-17
  • 打赏
  • 举报
回复
你在源文件中是否和这里帖出来的代码一样? 有可能是源文件中结构体的定义之后少了";"
如果没有少, 那么仔细检查你这段代码之前或者之后的代码是否少了";"

最好能把你的源代码中18行之前和之后的代码都尽量贴出来看看.
小耸 2009-08-17
  • 打赏
  • 举报
回复
我确实是在英文输入法下输入的。
lijian22500 2009-08-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jinwei1984 的回复:]
; 是在英语输入法下的 符号么?
[/Quote]
看看中英输入
小耸 2009-08-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jinwei1984 的回复:]
; 是在英语输入法下的 符号么?
[/Quote]

是啊!!!
yuhudie203 2009-08-17
  • 打赏
  • 举报
回复
检查下你的;替换为英文下的
jinwei1984 2009-08-17
  • 打赏
  • 举报
回复
; 是在英语输入法下的 符号么?

70,014

社区成员

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

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