CompuServe Messages

#MAllocate help

    30-Nov-94 21:05:21
Sb: #MAllocate help
Fm: Henry Williams 73527,1446
To: All
Hello people, I'm trying to allocate memory and fill it at the start of the program. When I get to the printf statement my array elements come out null. Does anyone have an idea what is wrong here. The data in my Names file is ok. Thank you for your advice. Henry #include <stdio.h> struct record{ char name[36]; int family; }; struct record *array; main() { FILE *in; int a=0, n=1; if ((array = (struct record *) malloc(33300)) == (FILE *) NULL){ fprintf (stderr, "\n Couldn't allocate memory!\n"); exit(10); } if (( in = fopen ("Names", "r")) == (FILE *) NULL ){ fprintf (stderr, "\n Couldn't read Name file!\n"); exit(10); } while (n == 1){ n = fread ( &array[a], sizeof (struct record), 1, in ); printf (" %-36s %d\n", array[a].name, array[a].family); a++; } free (array); fclose (in); }