struct syntax in c

Y

Yusuf

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;
}
 
S

Skarmander

Yusuf said:
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.

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.
 
Y

Yusuf

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top