c programming language
Dinosaurs love it!
c language
#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: \n");
for (x = 0; x < 20; x++) {
printf("Name > ");
rewind(stdin);
scanf("%[^\n]", 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("%[^\n]", mem.mem_mail);
printf("Address > ");
printf("\t\t City Name > ");
rewind(stdin);
scanf("%s", mem.addr);
printf("\t\t 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\n", mem.mem_name, mem.mem_gender, mem.mem_id, mem.mem_ic, mem.mem_num, mem.mem_mail, mem.addr, mem.addr);
}
fclose(memptr);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us