By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 986 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

struct syntax in c

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.