Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers LCC > Structures and ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 951 of 1062
Post > Topic >>

Structures and malloc at runtime

by bigpig@[EMAIL PROTECTED] May 31, 2007 at 12:38 PM

Please could someone look at the following code and see if with some
modifications it is possible to make it work:
I just want to allocate some memory at runtime for 500 structures (in
this example) and use it as in the example

Thank you
Carlos


struct data {
  char name[10];
  long age;
} ENTRY;

struct ENTRY * list1 = (struct ENTRY *)malloc(500 * sizeof(ENTRY));

strcpy(list1[1].name, "Hello");    (1)
list1[1].age = 5;

(1) will give the following errors:
unknown size for type 'incomplete struct ENTRY defined at....
unknown field 'name' of 'incomplete struct ENTRY defined at...
type error in argument 1 to 'strcpy'; found 'int' expected 'pointer to
char'
 




 4 Posts in Topic:
Structures and malloc at runtime
bigpig@[EMAIL PROTECTED]   2007-05-31 12:38:25 
Private Message
   2007-05-31 19:48:01 
Re: Structures and malloc at runtime
Richard Heathfield <rj  2007-05-31 19:55:27 
Re: Structures and malloc at runtime
CBFalconer <cbfalconer  2007-05-31 17:41:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 23 23:31:44 CDT 2008.