Re: how to initialize a structure
From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 10/29/03
- Next message: Dan Pop: "Re: arrow operator"
- Previous message: Sheldon Simms: "Re: Limiting Recursion Selectively"
- In reply to: Ramprasad A Padmanabhan: "how to initialize a structure"
- Next in thread: pete: "Re: how to initialize a structure"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Oct 2003 15:42:45 GMT
In <bnohft$13rf0i$1@ID-166953.news.uni-berlin.de> Ramprasad A Padmanabhan <ramprasad@netcore.co.in> writes:
>I have a simple structure defined like this
>
>struct userid {
> char uid[MAXUIDLENGTH];
> int insize;
> int outsize;
>};
>typedef struct userid user;
Don't typedef struct's, unless you have a *good* reason for doing it.
Saving a few keystrokes in declarations doesn't count as a good reason.
All you can achieve with gratuitous typedef's is render the code less
readable.
>Now I want to define a user array and initialize it
>
>I tried something like this but doesnt work
>
>user *list[] = {
> {"user1",10,20},
> {"user2",0,20},
> {"user3",11,2}
> };
>
>Is there a way I can initialize this array while its declaration.
You need to learn how to declare things in C. Your initialiser is OK,
your declaration isn't. You're declaring an array of pointers to user,
NOT an array of user.
Dan
-- Dan Pop DESY Zeuthen, RZ group Email: Dan.Pop@ifh.de
- Next message: Dan Pop: "Re: arrow operator"
- Previous message: Sheldon Simms: "Re: Limiting Recursion Selectively"
- In reply to: Ramprasad A Padmanabhan: "how to initialize a structure"
- Next in thread: pete: "Re: how to initialize a structure"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|