Advertisements
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:
- Change
size_t n_items = 0;
toint 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_t
s, so I suggest the second of the changes above.