我有错误说没有重载函数“calMean”的实例与参数列表匹配
这是我的代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FILE_NAME 20
#define LIST_SIZE 50
float calMean(RECORD list[], int count)
typedef struct
{
char *name;
int score;
}RECORD;
int main (void)
{
// Declarations
float mean;
FILE *fp;
char fileName[FILE_NAME];
RECORD list[LIST_SIZE];
char buffer[100];
int count = 0;
int i;
// Statements
printf("Enter the file name: ");
gets(fileName);
fp = fopen(fileName, "r");
if(fp == NULL)
printf("Error cannot open the file!\n");
while(fgets(buffer, 100, fp) != NULL)
{
if( count >= LIST_SIZE)
{
printf("Only the first 50 data will be read!\n");
break;
}
if( count < LIST_SIZE)
{
list[count].name = (char*) malloc(strlen(buffer)*sizeof(char));
sscanf(buffer,"%[^,], %d", list[count].name, &list[count].score);
printf("name is %s and score is %d\n", list[count].name, list[count].score);
count++;
}
for( i =0; i < (LIST_SIZE - count); i++)
{
list[count + i].name = 0;
list[count + i].score = 0;
}
}
printf("Read in %d data records\n", count);
mean = calMean(list, count);
fclose(fp);
return 0;
}
float calMean(RECORD list[], int count)
{
float tempMean;
int sum;
int i;
for(i = 0; i < count; i++)
sum += list[i].score;
tempMean = sum/count;
return tempMean;
}
错误发生在 main 中 calMean 函数的函数调用中,我是结构新手,所以我认为我在 calMean 函数调用中编写列表参数列表的方式是错误的,有没有办法解决这个问题?我正在尝试计算结构中成员分数的平均值。