语法错误 [英] syntax errror

查看:89
本文介绍了语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构:


typedef struct {

char magicNum [2];

int width;

int height;

int maxGrey;

int pixels [ROW] [COLUMN];

} ImageT;


当我尝试编写此声明时:


fscanf(infile,"%c",ImageT.magicNum [0]);


有一个错误信息说:


错误:''ImageT'之前的语法错误


这是什么原因?我在这里做错了什么?

谢谢。

I have a structure :

typedef struct{
char magicNum[2];
int width;
int height;
int maxGrey;
int pixels[ROW][COLUMN];
} ImageT;

When I try to code this statement:

fscanf(infile, "%c", ImageT.magicNum[0]);

there is an error messege saying:

error: syntax error before ''ImageT''

What''s the reason for that? What am I doing wrong here?
thanks.

推荐答案

请在此处粘贴您的代码。上面的代码段是不够的。

Please paste your code here. The code segment above is not enough.


" danu" <哒**** @ gmail.com>写道:
"danu" <da****@gmail.com> writes:
typedef struct {
char magicNum [2];
int width;
int height;
int maxGrey;
int pixels [ROW] [COLUMN];
} ImageT;

当我尝试编写此声明时:

fscanf(infile,"%c" ;,ImageT.magicNum [0]);

有一个错误信息说:

错误:''ImageT''之前的语法错误
typedef struct{
char magicNum[2];
int width;
int height;
int maxGrey;
int pixels[ROW][COLUMN];
} ImageT;

When I try to code this statement:

fscanf(infile, "%c", ImageT.magicNum[0]);

there is an error messege saying:

error: syntax error before ''ImageT''



你定义了一个结构类型并给它一个typedef名称ImageT。

你没有定义任何ImageT类型的对象。

的。操作员可以处理对象,而不是类型。

-

给我们所有人的教训:即使在琐事中也有陷阱。

--Eric Sosman



You defined a structure type and gave it a typedef name ImageT.
You didn''t define any object of type ImageT.
The . operator works on objects, not on types.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman


danu写道:

我有一个结构:

typedef struct {
char magicNum [2];
int width;
int height;
int maxGrey;
int pixels [ROW] [COLUMN];
} ImageT;

当我尝试编写此声明时:

fscanf(infile,"%c",ImageT.magicNum [0]);
<有一个错误信息说:

错误:''ImageT'之前的语法错误

原因是什么?我在这里做错了什么?
谢谢。

I have a structure :

typedef struct{
char magicNum[2];
int width;
int height;
int maxGrey;
int pixels[ROW][COLUMN];
} ImageT;

When I try to code this statement:

fscanf(infile, "%c", ImageT.magicNum[0]);

there is an error messege saying:

error: syntax error before ''ImageT''

What''s the reason for that? What am I doing wrong here?
thanks.




因为ImageT是一种类型,而不是变量。


您需要声明一个类型为ImageT的变量,例如:


ImageT MyImage;


然后:


fscanf(infile,"%c",& MyImage.magicNum [0]);


(请注意& ;传递char的地址。)


-

+ ----------------- -------- + -------------------- + -------------------- --------- +

| Kenneth J. Brody | www.hvcomputer.com | |

| kenbrody / at\spamcop.net | www.fptech.com | #include< std_disclaimer.h> |

+ ------------------------- + -------------- ------ + ----------------------------- +

不要给我发电子邮件:< mailto:Th ************* @ gmail.com>



Because ImageT is a type, not a variable.

You would need to declare a variable of type "ImageT", such as:

ImageT MyImage;

and then:

fscanf(infile, "%c", &MyImage.magicNum[0]);

(Note that "&" to pass the address of the char.)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>


这篇关于语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆