通讯录管理
#ifndef _CONTACT_H_
#define _CONTACT_H_
#include <stdio.h>
#include <assert.h>
#include <windows.h>
#pragma warning(disable:4996)
#define NAME_SIZE 32
#define SEX_SIZE 8
#define TELPHONE_SIZE 16
#define ADDRESS_SIZE 128
#define INIT_NUM 2
#define INC_SIZE 2
#define SAVE_FILE "save.txt"
typedef struct person{
char name[NAME_SIZE];
char sex[SEX_SIZE];
int age;
char telphone[TELPHONE_SIZE];
char address[ADDRESS_SIZE];
}person_t;
typedef struct contact{
int cap;
int size;
person_t friends[0];
}contact_t;
void InitContact(contact_t **ct);
void AddFriend(contact_t **ct);
void ShowContact(contact_t *ct);
void SearchFriend(contact_t *ct);
void ClearContact(contact_t *ct);
void DelFriend(contact_t *ct);
void SortContact(contact_t *ct);
void SaveContact(contact_t *ct);
#endif
#include "contact.h"
void InitContact(contact_t **ct)
{
FILE *fp = fopen(SAVE_FILE, "rb");
if (fp == NULL){
*ct = (contact_t *)malloc(sizeof(contact_t)+INIT_NUM*sizeof(person_t));
if (*ct == NULL){
perror("malloc");
exit(1);
}
(*ct)->size = 0;
(*ct)->cap = INIT_NUM;
printf("Using Default Init!\n");
}
else{
contact_t temp;
fread(&temp, sizeof(contact_t), 1, fp);
*ct = (contact_t *)malloc(sizeof(contact_t)+temp.cap * sizeof(person_t))