57 lines
826 B
C
57 lines
826 B
C
#include <stdio.h>
|
|
|
|
typedef enum Flags
|
|
{
|
|
FLAG_NONE = 0,
|
|
FLAG_HUNGRY = 1 << 1,
|
|
FLAG_THIRSTY = 1 << 2,
|
|
FLAG_SLEEPY = 1 << 3,
|
|
// TODO: add another flag
|
|
}Flags;
|
|
/*
|
|
* Instead of shifting you can also just write the value
|
|
* enum Flags
|
|
* {
|
|
* foo = 1,
|
|
* bar = 2,
|
|
* baz = 4,
|
|
* }
|
|
*/
|
|
|
|
void Set(Flags *flag, Flags value)
|
|
{
|
|
// TODO: Implement this.
|
|
}
|
|
|
|
int isSet(Flags flag, Flags value)
|
|
{
|
|
// TODO: Implement this
|
|
return 0;
|
|
}
|
|
|
|
typedef enum
|
|
{
|
|
GENDER_MALE,
|
|
GENDER_FEMALE,
|
|
}gender;
|
|
|
|
typedef struct person
|
|
{
|
|
char *Name;
|
|
int Age;
|
|
gender Gender;
|
|
Flags Condition;
|
|
}person;
|
|
|
|
int main(int argc, const char *argv[])
|
|
{
|
|
person Charly = {"Charly", 10, GENDER_MALE, FLAG_NONE};
|
|
|
|
Set(&Charly.Condition, FLAG_HUNGRY|FLAG_SLEEPY);
|
|
|
|
if(isSet(Charly.Condition, FLAG_SLEEPY))
|
|
{
|
|
printf("Charly is sleepy.");
|
|
}
|
|
}
|