And what did it print out for you?
You are getting the wrong values because it's working from random junk in the copy of info[50] in main.
C does not initialize arrays to 0... whatever random values are in memory where an array is created will be what you get.
Try it like this...
Code:
#include <stdio.h>
int fill_array(void);
int display_array(int count);
typedef struct
{
char worker_name[20];
float hourly_pay;
int hours;
}WorkerRecord;
int main()
{
WorkerRecord info[50];
int count, k;
float average_wage;
count = fill_array(info, 50);
display_array(info, count);
for(k = 0, average_wage = 0; k < count; k++)
{
average_wage += info[k].hourly_pay;
}
average_wage /= count;
printf("\nAverage Hourly Wage: $%.2f", average_wage);
printf("\n\nPress any key to continue...");
getchar();
return 0;
}
int fill_array(int *arr, int max)
{
int count = 0;
FILE * pointer;
pointer = fopen("workers.txt", "r");
if(pointer == NULL)
{
printf("The file can not be found.\n\n\n");
printf("Press any key to continue...");
getch();
exit(1);
}
while {fscanf(pointer, "%s%d%f", arr[count]->worker_name, &arr[count]->hours, &arr[count]->hourly_pay) > 2)
{
count++;
if (count >= max)
break;
}
fclose(pointer);
return (count);
}
int display_array(int *arr, int count)
{
int k;
float grosspay[50];
printf(" Name\t\tHours\t\tHourly Pay\tGross Pay\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
for(k = 0; k < count; k++)
{
gross_pay[k] = (arr[k]->hourly_pay * arr[k]->hours);
}
for(k = 0; k < count; k++)
{
printf("%s\t\t%d\t\t$%.2f\t\t$%.2f\n", arr[k]->worker_name, arr[k]->hours, arr[k]->hourly_pay, gross_pay[k]);
}
return 0;
}