我几乎完成了我的程序。问题是,我在使用指针进行调试时遇到了一些小问题。我想要一些关于如何修复它的帮助。请注意,我确实需要我所有的函数原型。(如果我能在 main 中做所有事情,分配会容易得多......)
#include <stdio.h>
#include <stdlib.h>
#define STUDENTS 5
int getData(int *student, char *pass, int *hw1, int *hw2, int *hw3, int *hw4,
int *hw5, int *hw6, int *hw7, int *mid1, int *mid2, int *final,
int *extra);
float calcAvg(float *total);
float printTable(int student, float total);
int main(void)
{
int student[STUDENTS];
char pass[STUDENTS];
int hw1[STUDENTS], hw2[STUDENTS], hw3[STUDENTS], hw4[STUDENTS], hw5[STUDENTS], hw6[STUDENTS], hw7[STUDENTS];
int mid1[STUDENTS], mid2[STUDENTS];
int final[STUDENTS];
int extra[STUDENTS];
float total[STUDENTS];
getData(student, pass, hw1, hw2, hw3, hw4, hw5, hw6, hw7,
mid1, mid2, final, extra);
calcAvg(total);
printTable(student, total);
system("pause");
return 0;
}
int getData(int *student, char *pass, int *hw1, int *hw2, int *hw3, int *hw4,
int *hw5, int *hw6, int *hw7, int *mid1, int *mid2, int *final,
int *extra)
{
FILE *fpIn;
int i;
fpIn = fopen("data.txt", "r");
if (!fpIn)
{
printf("File does not exist.");
system("pause");
exit (101);
}
for (i=0; i<STUDENTS; i++)
{
fscanf(fpIn, "%d", &student[i]);
fscanf(fpIn, "%c", &pass[i]);
fscanf(fpIn, "%d %d %d %d %d %d %d", hw1[i], hw2[i], hw3[i], hw4[i], hw5[i], hw6[i], hw7[i]);
fscanf(fpIn, "%d %d", mid1[i], mid2[i]);
fscanf(fpIn, "%d %d", final[i], extra[i]);
}
return;
}
float calcAvg(float *total)
{
int hwtotal[STUDENTS], midtotal[STUDENTS];
int i;
for (i=0; i<STUDENTS; i++)
{
hwtotal[i] = hw1[i]+ hw2[i]+hw3[i]+hw4[i]+hw5[i]+hw6[i]+hw7[i];
midtotal[i] = mid1[i]+mid2[i];
total[i] = (hwavg[i]+midavg[i]+final[i]+extra[i])/3;
}
return total;
}
float printTable(int student, float total)
{
int i;
printf("==== ======= =======\n");
printf(" ID Score Grade\n");
printf("==== ======= =======\n");
for(i=0; i<STUDENTS; i++)
{
printf("%d .1f ", student[i], total[i]);
if (total>90)
printf("A\n");
else if(total>80);
printf("B\n");
else if (total>70);
printf("C\n");
else if (total>60);
printf("D\n");
else
printf("F\n");
}
return;
}