#include <stdio.h>
#pragma warning (disable:4996)
struct address {
char city;
int cCode;
};
typedef struct {
char mem_name[25];
char mem_gender;
char mem_mail;
int mem_id;
int mem_ic;
int mem_num;
struct address addr;
} member;
int main() {
FILE* memptr;
member mem;
int x;
memptr = fopen("Member Info.bin", "wb");
if (!memptr) {
printf("Unable to open the file, please try again");
}
else {
printf("Enter your details:
");
for (x = 0; x < 20; x++) {
printf("Name > ");
rewind(stdin);
scanf("%[^
]", mem.mem_name);
printf("Gender (M = male, G = female) > ");
rewind(stdin);
scanf("%s", mem.mem_gender);
printf("Member ID > ");
rewind(stdin);
scanf("%d", mem.mem_id);
printf("NRIC (without -) > ");
rewind(stdin);
scanf("%d", mem.mem_ic);
printf("Contact Number > ");
rewind(stdin);
scanf("%d", mem.mem_num);
printf("Email > ");
rewind(stdin);
scanf("%[^
]", mem.mem_mail);
printf("Address > ");
printf(" City Name > ");
rewind(stdin);
scanf("%s", mem.addr);
printf(" City Code > ");
rewind(stdin);
scanf("%d", mem.addr);
fwrite(&mem, sizeof(member), 1, memptr);
}
fclose(memptr);
}
memptr = fopen("Member Info.bin", "rb");
for (x = 0; x < 20; x++) {
fread(&mem, sizeof(member), 1, memptr);
printf("%s|%s|%d|%d|%d|%s|%s|%d
", mem.mem_name, mem.mem_gender, mem.mem_id, mem.mem_ic, mem.mem_num, mem.mem_mail, mem.addr, mem.addr);
}
fclose(memptr);
}