// and we sell computer softwares
struct software_info_t { // a structure containing various bitfields
unsigned int plateform : 2; // 2 bits reserved for the plateform - plateforms can be combined (0x03) #define PC 0x1 // 0x01 #define MAC 0x2 // 0x02
unsigned int os : 3; // 3 bits reserved for the OS - OS can be combined (0x1C) #define WINDOWS 0x1 // 0x04 #define DOS 0x2 // 0x08 #define OS_X 0x4 // 0x10
unsigned int category : 2; // 2 bits reserved for the category - categories can't be combined (0x60)
#define DISASSEMBLY 0x1 // 0x20 #define RECOVERY 0x2 // 0x40 #define CRYPTOGRAPHY 0x3 // 0x60 };
struct software_t { software_info_t info; char name[32]; };
struct softwares_t { // a variable length structure to memorize our softwares long count; software_t softs[]; };
// generic products we're selling
enum product_category_t { // an enumerated type BOOK,
SOFTWARE,
HARDWARE // we actually don't sell hardware };
union product_u { // an union to contain product information depending on its category book_t book; software_t software;
// struct hardware_t hardware; // we actually don't sell hardware };
struct product_t { // a structure containing another structure long id;
product_category_t category; product_u p; };
// our data // ======== // our customers
customer_t customers[] = { // an initialized array to memorize our customers { 1, \ { 2, \ { 3, \ { 0 } };
// our products
book_t ida_book = { \
softwares_t softwares = // an initialized variable length structure { 3, {
{ { PC, WINDOWS|DOS, DISASSEMBLY }, \ { { PC|MAC, WINDOWS|OS_X, RECOVERY }, \ { { PC, WINDOWS, CRYPTOGRAPHY }, \ } };
#define PRODUCTS_COUNT 4
// our functions // =============
// check software information
int check_software(software_info_t software_info) {
bool valid = true;
if (software_info.plateform & PC) {
if (! (software_info.plateform & MAC) && (software_info.os & OS_X)) valid = false; // OS-X isn't yet available on PC ;) }
else if (software_info.plateform & MAC) {
if (! (software_info.plateform & PC) && ((software_info.os & WINDOWS) || (software_info.os & DOS)))
valid = false; // Windows & DOS aren't available on Mac... } else
valid = false; return valid; }
// check product category
int check_product(product_category_t product_category) {
bool valid = true;
if (product_category == HARDWARE) {
valid = false;
printf(\ }
return valid; }
// print customer information
void print_customer(customer_t *customer) {
printf(\customer->id, customer->name, customer->sex); }
// print book information
void print_book(book_t *book) {
printf(\book->title); }
// print software information
void print_software(software_t *software) {
printf(\software->name); // plateform
// we use 'if', as plateforms can be combined if (software->info.plateform & PC) printf(\
if (software->info.plateform & MAC) printf(\ printf(\ // OS
// we use 'if', as os can be combined if (software->info.os & WINDOWS) printf(\ if (software->info.os & DOS) printf(\
if (software->info.os & OS_X) printf(\ printf(\ // category
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库IDA简易教程(10)在线全文阅读。
相关推荐: