#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FILE_NAME  20
#define LIST_SIZE 50

float calMean(RECORD list[].score, 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[].score, count);        
       fclose(fp);
       return 0;
}


float calMean(RECORD list[].score, int count)
{
    float tempMean;
    int sum;
    int i;
    for(i = 0; i < count; i++)
        sum += list[i].score;
    tempMean = sum/count;

    return tempMean;
}

i have an error saying that no instance of overloaded function "calMean" matches the argument list at calMean function call. I'm new to structure so I think that the way i write list in calMean function call may not be correct. Is there any suggestion to how I can fix this error?
thank in advance

There are a couple of problems.
1. In your function prototype you have declared and defined a function which has RECORD list[].score listed as the type for the first parameter, which isn't a type at all. This is nonsense!
2. Where you're calling the function you are passing list[].score, which would equate to an int (at least it would if you had given it an index), which could go some way to explaining why you're getting errors about not being able to find a matching function.

You need to pass the entire array to the function. So you should change the signature of the function to:
float calMean(RECORD list[], int count)

Once you've done that, the rest of the code inside your function should work. But you should note that your division operation consists of two int values. And an int divided by an int will return an int. In order to get a float result, you'll need to cast at least one of the two values to float. e.g. return ((float)sum)/count);

And you call the function like this:
mean = calMean(list, count);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.