I have this simple code:
#include <stdio.h>
#include <time.h>
int main(){
enum Days { asd=0,Lun,Mar,Mer,Gio,Ven,Sab,Dom };
Days TheDay;
time_t ltime;
struct tm *Tm;
ltime=time(NULL);
Tm=localtime(<ime);
int j = Tm->tm_wday;
TheDay = Days(j);
printf("[%d] %d/%d/%d, %d:%d:%d\n",
TheDay, /* Mon - Sun */
Tm->tm_mday,
Tm->tm_mon,
Tm->tm_year+1900,
Tm->tm_hour,
Tm->tm_min,
Tm->tm_sec);
}
I don't understand why I'm getting this error:
try.c:6:5: error: unknown type name ‘Days’
This is not C:
enum Days { asd=0,Lun,Mar,Mer,Gio,Ven,Sab,Dom };
Days TheDay;
The name of the new type is enum Days
and not Days
(which is the enum tag).
You have to use:
enum Days { asd=0,Lun,Mar,Mer,Gio,Ven,Sab,Dom };
enum Days TheDay;
or use a typedef:
typedef enum Days Days;
to be able to use Days
as a type name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With