I am unable to compile the following code because my gcc compiler (MSYS2 12.1.0) is not recognizing the struct that I have created in my header file diffDates.h.
Below is the header file
#ifndef DIFFDates_H
#define DIFFDates_H
int getDifference(Date dt1, Date dt2);
// A date has day 'd', month 'm' and year 'y'
struct Date {
int d, m, y;
};
#endif
Below is my main file makefiles.c
#include <stdio.h>
#include <string.h>
#include "diffDates.h"
int main()
{
char str_start[10];
char str_end[10];
printf("Please enter the start date in dd.mm.yy: ");
scanf("%s", str_start);
printf("\nPlease enter the end date in dd.mm.yy:");
scanf("%s", str_end);
return 0;
}
Below is the output from the GCC compiler
gcc makefiles.c -o makefiles
In file included from makefiles.c:7:
diffDates.h:4:19: error: unknown type name 'Date'
4 | int getDifference(Date dt1, Date dt2);
| ^~~~
diffDates.h:4:29: error: unknown type name 'Date'
4 | int getDifference(Date dt1, Date dt2);
| ^~~~
diffDates.h:19:20: error: unknown type name 'Date'
19 | int countLeapYears(Date d)
| ^~~~
diffDates.h:40:19: error: unknown type name 'Date'
40 | int getDifference(Date dt1, Date dt2)
| ^~~~
diffDates.h:40:29: error: unknown type name 'Date'
40 | int getDifference(Date dt1, Date dt2)
|
I would like to know what is wrong because I can include functions in the main file but structs are not defined for some reason.