by CBFalconer <cbfalconer@[EMAIL PROTECTED]
>
May 31, 2007 at 05:41 PM
bigpig@[EMAIL PROTECTED]
wrote:
>
> 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
>
> struct data {
> char name[10];
> long age;
> } ENTRY;
This declares a data item of type struct data named ENTRY. Please
don't use upper case for data names, reserve the upper case for
macros.
>
> struct ENTRY * list1 = (struct ENTRY *)malloc(500 * sizeof(ENTRY));
This should create a compiler error. Replace "ENTRY" with "data".
Also eliminate the cast. You are obviously using C, not C++, and
the cast can only hide errors. Have you #included <stdlib.h> ?
>
> 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'
Now I expect the above code will work.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com