I have a problem with this piece of code here. What my code is supposed to do is to assign bitfields to weekdays. For example, 0x00 for Monday, 0x01 for Tuesday and so on. Here is my code:
#include<stdio.h>
typedef struct
{
unsigned int week:3;
unsigned int month:4;
}datum;
void date(datum *d, char wday[])
{
switch(d->week)
{
case 0x00:
*wday = "Monday";
break;
case 0x01:
*wday = "Tuesday";
break;
default:
printf("Unknown option: %i\n", d->week);
}
}
int main()
{
char wday[]="";
datum now = {0x01, 0x05};
date(&now,&wday);
printf("It's %s\n", wday);
return 0;
}
At this point, what my code is SUPPOSED to do when I run it (and if I could at least compile it), is to show:
It's Monday
Unfortunately it does either not compile or when I make changes with the pointers it shows for example "It's -88". I think the problem lies with the char pointers to char wday. But I have no idea how to make my code work.
Thank you very much for helping out a C-Rookie.