Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!rit!ritcsh!sabin!bjm From: bjm@sabin.UUCP (Brendan J. McMahon) Newsgroups: comp.lang.c Subject: malloced structure initilization Message-ID: <202@sabin.UUCP> Date: 8 Feb 89 16:09:19 GMT Reply-To: bjm@sabin.UUCP (Brendan J. McMahon) Organization: Sabin Metal Corp., Scottsville, NY Lines: 38 /* Simple problem - How do you initialize memory malloced for a structure without using calloc, and without initilizing each structure element explicitly? Example -- */ #include #include struct foo{ int a; long b; char c[80]; double d; }; main() { struct foo *fooptr; if ( (fooptr=(struct foo *)malloc(sizeof(struct foo))) == NULL){ puts("Malloc Bombed"); exit(-1); } func(fooptr); } func(fooptr) struct foo *fooptr; { struct foo *fp2; for(fp2=fooptr; fp2 < fooptr + sizeof(struct foo); fp2++) *fp2=NULL; /* Error - incompatible types */ }