Hello again,
Thanks to Salem for the previous help, but I still can't seem to work this out...
I apologize to all.
Before I had asked to read many different struct-like records, dynamically allocate memory for each and then print them to stdout, but it would seem something for linked-lists and I'd prefer to avoid this. So it would be simpler to just read only *one* struct-like info file and then print to stdout.
Here's the file to read from disk, called "struct holidays":
{1, 15, "Seijin no hi (Coming of Age Day)"},
{2, 11, "Kenkoku Kinenbi (National Foundation Day)"},
{3, 20, "Shunbun no hi (Equinox Day)"},
{4, 29, "Midori no hi (Greenery Day)"},
{5, 3, "Kenpou kinenbi (Constitution Day)"},
{6, 20, "Chi-chi no hi* (Father's Day, third Sunday in June)"},
{7, 25,"Umi no hi (Sea/Marine Day)"},
{8, 15, "Shuusen Kinenbi* (End of WWII)"},
{9, 15, "Keiro no hi (Senior's Day)"},
{10, 10, "Taiku no hi (Physical Education Day)"},
{11, 3, "Bunka no hi (Culture Day)"},
{12, 23, "Tennou Tanjoubi (Emperor's Birthday)"}
Here is my code, which covers two requirements;
1. use malloc or calloc (or realloc if necessary),
2. use the arrow operator to access the infile data.
struct holidays *readIn;
FILE *pHolidays;
int count = 0;
int size = sizeof (struct holidays);
readIn = (struct holidays *) malloc (sizeof (struct holidays));
if ((pHolidays = fopen ("InputFile", "rb")) == NULL)
{
fputs ("\nUnable to open InputFile", stderr);
exit (1);
}
while (fread (readIn, size, 1, pHolidays) == 1)
{
printf ("\n %d %d %s", readIn->month, readIn->day, readIn->holidayName);
count++; //appears rather useless here I realize...
}
The ouput usually ends up reading from lines 3, 6, 8 or 9 of the input file and prints garbage chars for the end of the holiday names list.
Thank you for reading this and for any and all previous help, as well as the professionalism and courtesy that is always received...
inakappeh