Click here to Skip to main content
15,793,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ALL,

I have a structure in C as follow:
Static struct{
              int  aaa;
              char bbb;
              int  ccc;
              char ddd;

and I set value for it as below:

So I set value for form is correct or not?
I need your answer as soon as possible!

Updated 19-Jan-11 22:57pm
justinonday 12-Jan-11 23:07pm    
Arrays of structure starts with Zero....

Actually your code is not correct, but I will leave it to you to look up what zero-based indexing is and you will understand what is wrong.
Share this answer
HimanshuJoshi 12-Jan-11 23:05pm    
Thanks Marcus, I should have paid more attention.
Dalek Dave 13-Jan-11 3:43am    
Making the poor bugger work? :)
Espen Harlinn 17-Jan-11 13:57pm    
5+ Instructive answer :)
Besides the indexing mistake, something else is wrong too.
The proposed method of initialising a structure can be used only in the declaration, not afterward.

So this would be fine:
static struct{
    int  aaa;
    char bbb;
    int  ccc;
    char ddd;
}form[2] = {8,'a',6,'b',9,'s',5,'v'};

But to modify it later, you would have to do it like this:
form[1].aaa =  9;
form[1].bbb = 's';
form[1].ccc =  5;
form[1].ddd = 'v';
Share this answer
fjdiewornncalwe 13-Jan-11 9:30am    
Good catch... That didn't hit me last night.
The answer is Yes No; If you have access to a computer and a c compiler, then you should figure this out yourself.
Share this answer
fjdiewornncalwe 12-Jan-11 22:56pm    
Zero based indexing, Himanshu... :) I'm leaving it up to the OP to search up on that to see the error in his ways.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900