But how do I pass the arrays when I call the function in main? I'm not understanding this part.
Here is my code:
Code:
void payrate(double *rate);
void Summary();
main()
{
FILE *fp2;
int empnum[6], paygroup[6], n;
char lastn[6][12];
char firstn[6][12];
double hours[6];
double gross[6];
double rate[10];
int OT;
fp2=fopen("emp.txt", "r");
if (fp2 == NULL){
printf("Error; No file detected\n");
exit(1);
}
for(n=0;n<6;n++){
fscanf(fp2, "%d:%[^:]:%[^:]:%d:%lf\n", &empnum[n], lastn[n], firstn[n], &paygroup[n], &hours[n]);
}
for(n=0;n<6;n++){
printf("\n%04d, %s, %s, %d, %.1lf\n", empnum[n], lastn[n], firstn[n], paygroup[n], hours[n]);
if(hours[n]>44){
printf("\nrate is %.2lf\n", rate[n]);
gross[n] = hours[n]*rate[n];
printf("Gross is %.2lf", gross[n]);
}
}
fclose(fp2);
// gross pay //
payrate(rate);
Summary();
scanf("%d");
}
void payrate(double *rate){
FILE *fp1;
int i, n;
double payrate[10];
fp1=fopen("payrates.txt", "r");
if (fp1 == NULL){
printf("Error; No file detected\n");
exit(1);
}
for(i=0;i<15;i++){
fscanf(fp1, "%lf\n", &rate[i]); //scans file//
}
for(i=0;i<10;i++){
printf("%.2lf \n", rate[i]); //output payrate//
}
fclose(fp1);
}
I need to pass the 'rate' in each array from the 'void payrate' function.
I thought it would be something like:
void payrate(double *rate[i])
or something to that effect.
Can you please clarify?