I am creating a program, which involves data from file. In one of the functions i get the error incompatible types when initializing type 'int' using type 'datte' when i try to compile it
datte, clocck and games are structs.
games create_match(int round, int goals_home_team, int goals_visiting_team, int spectators, char home_team[MAX_TEAM_NAME], char visiting_team[MAX_TEAM_NAME],
datte day,
clocck otim)
{
games result = { round, day, otim, "", "", goals_home_team, goals_visiting_team, spectators };
strcpy(result.home_team, home_team);
strcpy(result.visiting_team, visiting_team);
return result;
}
My compiler says that the error is at the line "games result =re...".
I have another function from another program, which is identical, but that one has no problem compiling
kamp, dato and klokke are structs
kamp lav_kamp(int runde, dato dato, klokke klokke,
char hjemmehold[MAX_HOLD_NAVN], char udehold[MAX_HOLD_NAVN],
int hjemmemaal, int udemaal, int tilskuere)
{
kamp res =
{ runde, dato, klokke, "", "", hjemmemaal, udemaal, tilskuere };
strcpy(res.hjemmehold, hjemmehold);
strcpy(res.udehold, udehold);
return res;
}
So what i don't understand is why the first function can't compile, but the second one can.
EDIT:
The 3 structs
typedef struct games
{
int round_of_games,
spectators,
goals_home_team,
goals_visiting_team;
char home_team[MAX_TEAM_NAME],
visiting_team[MAX_TEAM_NAME];
clocck otim;
datte datte;
} games;
typedef struct clocck
{
int tim_hour,
tim_min;
} clocck;
typedef struct datte
{
int odate_day,
odate_year;
enum odate_month
{
January, February, March, April, May, June, July, August, Septemper, October, November, December
} odate_month;
} datte;
The problem is that you can't just initialize a structure in any order, you must initialize it in the exact order the member fields was declared in the structure.
For example, in your games
structure you declared the datte
member last, as the eight member. That means that the day
variable in your create_match
function must be the last in the initialization.
So instead of e.g.
games result = { round, day, ... };
You must write
games result = { round, ..., day };
You must also make sure the other values in the initialization of result
is in the correct order in the structure.