468,513 Members | 1,874 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

struct syntax in c

Hi friends, I'm reading and reading page 128-130 of K&R ANSI edition
and I cannot understand structs. My most simple program gives me the
error

t2.c:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before
'.' token

I know this is a trivial question to members of this group so could
someone put me on the right track with the syntax. My c program,
compiled with gcc4.1 is below. The error line, line 10, is "
test.testint=1;"

Thank you
Yusuf

struct teststr
{
int testint;
long testlong;
short testshort;
};

struct teststruct test;

test.testint=1;

int main(void)
{
return 0;
}

Sep 23 '06 #1
2 5188
Yusuf wrote:
Hi friends, I'm reading and reading page 128-130 of K&R ANSI edition
and I cannot understand structs. My most simple program gives me the
error
You don't have a problem with structs.

<snip>
struct teststr
{
int testint;
long testlong;
short testshort;
};

struct teststruct test;

test.testint=1;
Statements cannot appear outside functions. Declarations can.
int main(void)
{
Put the declaration and the assignment here.
return 0;
}
S.
Sep 23 '06 #2
Thank you so much. As you can guess, I'm learning c.
Regards
Yusaf

struct teststruct
{
int testint;
long testlong;
short testshort;
};

int main(void)
{
struct teststruct test;
test.testint=1;
return 0;
}

Sep 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Martin Pohlack | last post: by
3 posts views Thread by Roland Dreier | last post: by
3 posts views Thread by Emanuele Blanco | last post: by
11 posts views Thread by Magix | last post: by
19 posts views Thread by Russell Shaw | last post: by
9 posts views Thread by werasm | last post: by
12 posts views Thread by Yusuf | last post: by
14 posts views Thread by Lane Straatman | last post: by
28 posts views Thread by Bill | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.