(This is about finding what’s wrong with my program) I am quite new to programming and I am currently learning how to use structures and nodes in C and I made this simple program that is supposed to read and register the data of a movie, but I don’t know what am I doing wrong as my compiler keeps showing this:
•Calling ‘fillMovieData’ with incomplete return type ‘struct node’ (at line 17)
•incomplete result result type ‘struct node’ in function definition (at line 22)
•returning ‘struct cinema’ from a structure with incompatible result type ‘struct node’ (at line 32)
do you know how can I fix this errors?, I’ll appreciate all the feedback I can get!
The code is:
#include<stdio.h>
#include<stdlib.h>
struct cinema{
char *name;
char *genre;
short year;
short numDirectors;
char *directors[10];
};
void printMovieData(struct cinema);
struct node fillMovieData(char *, char *, short , short , char *[10]);
int main(){
char *directors[10];
directors[0] = "Lana Wachowski";
directors[1] = "Andy Wachowski";
struct cinema matrix = fillMovieData("The matrix", "Fiction", 1999, 2, directors); // this is line 17
printMovieData(matrix);
return 0;
}
struct node fillMovieData(char *name, char *genre, short year,short numDirectors, char *directors[10]){ //this is line 22
struct cinema movie;
movie.name = name;
movie.genre = genre;
movie.year = year;
movie.numDirectors = numDirectors;
int cont = 0;
for ( ; cont < movie.numDirectors ; cont++){
movie.directors[cont] = directors[cont];
}
return movie; //this is line 32
}
void printMovieData(struct cinema movie){
printf("MOVIE: %sn", movie.name);
printf("GENRE: %sn", movie.genre);
printf("YEAR: %dn", movie.year);
printf("DIRECTOR(S):n");
int cont = 0;
for ( ; cont < movie.numDirectors ; cont++){
printf("%sn", movie.directors[cont]);
}
}
2
Answers
in line 17:
you define a movie data type
struct cinema matrix
but the function you usereturns a node data type
also line 22 and 32 try to say that you use different data type for returning value of fillMovieData function
returns type of
struct node
but in definition you returnmovie
which is type ofstruct cinema
data type.Your
fillMovieData
function is returning the value ofmovie
, which has typestruct cinema
. Also, you don’t have a definition for typestruct node
like you do forstruct cinema
.It’s clear to me that you meant to declare
fillMovieData
as.