Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

  • Change size_t n_items = 0; to
    int n_items = 0;
    
  • Change the function to
    void read_file(struct movie movie_list[], size_t *ptr_n_items)
    

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading