csize-t

incompatible pointer types passing 'size_t *' (aka 'unsigned long *') to parameter of type 'int *' [-Wincompatible-pointer-types]


I'm making a movie rating management program. I declared size_t as a data type to count, but I get this error. What's wrong with you?

int main(){
    struct movie movie_list[LMAX];
    size_t n_items = 0;

    read_file(movie_list, &n_items);
void read_file(struct movie movie_list[], int *ptr_n_items){ 

    for (int n = 0; n < num; ++n){
        if (fscanf(file, "%[^\n]%*c", movie_list[*ptr_n_items].title) != 1 || fscanf(file, "%f%*c", &movie_list[*ptr_n_items].rating) != 1){
            printf("ERROR: Wrong file format.\n");
            exit(1);
        }
        *ptr_n_items += 1;
    }

    assert(*ptr_n_items == num);

I don't know how to solve the error. Tell me how.


Solution

  • The problem is that you supply a size_t* to a function which expects an int*. You need to do one of these:

    The teacher's recommendation was to use size_ts, so I suggest the second of the changes above.