#include #include #include #include #include #include struct cat_struct { char name[16]; int age; int catches_per_month; }; void print_cat(struct cat_struct *toprint){ printf("Name: %s\nAge: %d\nCatchesPerMonth: %d\n", toprint->name, toprint->age, toprint->catches_per_month); } void main(){ char message[] = "There is a semiconductor in my cupcake"; printf("The data is: %s\n", message); printf("The data is: %lx\n", message); printf("message is %d bytes\n", sizeof message ); char *message_ref = message; printf("The data is: %s\n", message_ref); printf("The data is: %lx\n", message_ref); printf("message is %d bytes\n", sizeof message_ref); if(message == message_ref){ printf("They are equal\n"); } if(0 == strcmp(message, message_ref)){ printf("They have the same contents\n"); } int *iMessage = (int*)message; struct cat_struct *c = (struct cat_struct*)message; print_cat(c); c->age = 1400; print_cat(c); for(int i = 0; i < 10; i++){ printf("iMessage[%d] = %d\n", i, iMessage[i]); } int fd = open("catfile", O_WRONLY| O_CREAT); if(fd == -1){ perror("There was a problem with the file"); return; } write(fd, c, sizeof(struct cat_struct)); close(fd); }