diff --git a/周一展示代码2.0 (1) (4).c b/周一展示代码2.0 (1) (4).c new file mode 100644 index 0000000..2214d4c --- /dev/null +++ b/周一展示代码2.0 (1) (4).c @@ -0,0 +1,881 @@ +#include +#include + +#include +#include +#include +#include +#include +#pragma comment(lib,"winmm.lib") +#define MAX 1000 +#define NAME_MAX 20 +#define SEX_MAX 5 +#define ADDR_MAX 30 +#define TELE_MAX 12 +#define S_NUM 13 + + +#define BLACK 0 +#define BLUE 1 +#define GREEN 2 +#define CYAN 3 +#define RED 4 +#define MAGENTA 5 +#define BROWN 6 +#define LIGHTGRAY 7 +#define DARKGRAY 8 +#define LIGHTBLUE 9 +#define LIGHTGREEN 10 +#define LIGHTCYAN 11 +#define LIGHTRED 12 +#define LIGHTMAGENTA 13 +#define YELLOW 14 +#define WHITE 15 + + +#define T double +#define _CRT_SECURE_NO_WARNINGS 1 +#include +#include +#define error(message) { printf(message "\n"); fflush(stdout); system("pause"); exit(-1); } + +#ifndef MIN +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4 +#endif + +#define MID_FILE_PATH "001.mp3" +#define LYRIC_FILE_PATH "lyric.lrc" +#define PIC1_PATH "pic1.bmp" +#define PIC2_PATH "pic2.bmp" + + + +#pragma pack(1) +/* + +CYANɫ +MAGENTA: Ʒɫ +LIGHTGRAY: dzɫ + +*/ + +T c(T x,T y,T r) +{ + return sqrt(x*x+y*y)-r; +} +T u(T x,T y,T t) +{ + return x*cos(t)+y*sin(t); +} +T v(T x,T y,T t) +{ + return y*cos(t)-x*sin(t); +} +T fa(T x,T y) +{ + return fmin(c(x,y,0.5),c(x*0.47+0.15,y+0.25,0.3)); +} +T no(T x,T y) +{ + return c(x*1.2+0.97,y+0.25,0.2); +} +T nh(T x,T y) +{ + return fmin(c(x+0.9,y+0.25,0.03),c(x+0.75,y+0.25,0.03)); +} +T ea(T x,T y) +{ + return fmin(c(x*1.7+0.3,y+0.7,0.15),c(u(x,y,0.25)*1.7,v(x,y,0.25)+0.65,0.15)); +} +T ey(T x,T y) +{ + return fmin(c(x+0.4,y+0.35,0.1),c(x+0.15,y+0.35,0.1)); +} +T pu(T x,T y) +{ + return fmin(c(x+0.38,y+0.33,0.03),c(x+0.13,y+0.33,0.03)); +} +T fr(T x,T y) +{ + return c(x*1.1-0.3,y+0.1,0.15); +} +T mo(T x,T y) +{ + return fmax(c(x+0.15,y-0.05,0.2),-c(x+0.15,y,0.25)); +} +T o(T x,T y,T(*f) +(T,T),T i) +{ + T r=f(x,y);return fabs(r)<0.02?(atan2(f(x,y+1e-3)-r,f(x+1e-3,y)-r)+0.3)*1.273+6.5:r<0?i:0; +} +T s(T x,T y,T(*f)(T,T),T i) +{ + return f(x,y)<0?i:0; +} +T f(T x,T y) +{ + return o(x,y,no,1)?fmax(o(x,y,no,1),s(x,y,nh,12)):fmax(o(x,y,fa,1),fmax(o(x,y,ey,11),fmax(o(x,y,ea,1),fmax(o(x,y,mo,1),fmax(s(x,y,fr,13),s(x,y,pu,12)))))); +} + + + + + + + + + + + + + + + + + + +typedef union { + char user_name[20]; + char user_password[20]; +} User; + +// Աͬ壬ʹƣɰչԱ +typedef union { + char admin_name[20]; + char admin_password[20]; +} Administrator; + +// һṹͬ壬û͵ȸȨޱʶֶΣ +typedef struct { + int user_type; // 0ʾʹߣ1ʾԱɸʵչ + union { + User user; + Administrator admin; + } info; +} Person; +const char ADMIN_NAME[] = "a"; +const char ADMIN_PASSWORD[] = "1"; + +// ģͨʹû룬ʵʿɴļȶȡ֤ +const char USER_NAME[] = "u"; +const char USER_PASSWORD[] = "6"; + + + +//ԱϢ +typedef struct ContactMember +{ + char Name[NAME_MAX]; + char Sex[SEX_MAX]; + int Age; + char Number[TELE_MAX]; + char Address[ADDR_MAX]; + int Snumber; +}ContactMember; + +typedef struct Contact +{ + ContactMember ContactMembers[MAX]; + int sz; +}Contact; + +//ɫ +void SetColor(int ForgC, int BackC) { + WORD wColor; + HANDLE hStdOut; + + hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); + wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F); + SetConsoleTextAttribute(hStdOut, wColor); +} + + +//ʼͨѶ¼ +void InitContact(Contact* con); + +//ϵϢӵļĩβ +void AddContactToFile(ContactMember newContact, const char* filename); + +// ɾָϵˣͨƥɾ +void DeleteContact(Contact* con); + +// ͨѶ¼ṹеϵϢдصļ +void WriteContactToFile(Contact* con, const char* filename); + +//ָϵ +void SearchContact(Contact* con); + +// ޸ϵ˹ܺ +void ModifyContact(Contact* con, const char* filename); + +// ļȡϵϢͨѶ¼ṹ +void ReadContactFromFile(Contact* con, const char* filename); + +// ϵϢӵļĩβ +void AddContactToFile(ContactMember newContact, const char* filename); + +// չʾϵϢ +void ReadContact(Contact* con); + +// ϵˣڴգͬʱдļļݣ +void ClearContacts(Contact* con, const char* filename); + +//ϵ +void SortContacts1(Contact* con); + +//ѧϵ +void SortContactsBySnumber1(Contact* con); + +//ϵ +void SortContacts2(Contact* con); + +//ѧŽϵ +void SortContactsBySnumber2(Contact* con); + +// ¼ֵ֤ʾûͣ0Ϊʹߣ1ΪԱ-1ʾ¼ʧ +int login(Person *p); +//һļ +void loadContacts(Contact* con); +// +void saveContacts(Contact* con); + +void welcome() +{ + printf("*********************************\n"); + printf("********ӭʹͨѶ¼ϵͳ*******\n"); + printf("*********************************\n"); + printf("Q 1 !\n"); + printf("1----Yes 2----No\n"); +} + + + +void menu() +{ + printf("***************************************\n"); + printf("****** ͨѶ¼ **************\n"); + printf("****** 1. 2.ɾ **************\n"); + printf("****** 3. 4.޸ **************\n"); + printf("****** 5. 6. **************\n"); + printf("****** 7. 8.ɫ ******\n"); + printf("*****************0.˳****************\n"); + printf("***************************************\n"); +} + + +void yanse() +{ + printf("0----black 1----blue\n"); + printf("2----green 3----cyan\n"); + printf("4----red 5----magenta\n"); + printf("6----brown 7----lightgray\n"); + printf("8----darkgray 9----lightblue\n"); + printf("10----lightgreen 11----lightcyan\n"); + printf("12----lightred 13----lightmagenta\n"); + printf("14----yellow\n"); +} + + + +// WindowsAPImidƵ (ps: APImp3ҲǿԵ~) +BOOLEAN playMusic(const char* filePath) { + HMODULE module = LoadLibraryA("winmm.dll"); + + typedef MCIERROR(WINAPI* MciSendStringT)(LPCSTR lpstrCommand, LPSTR lpstrReturnString, UINT uReturnLength, HWND hwndCallback); + + MciSendStringT func_mciSendStringA = (MciSendStringT)GetProcAddress(module, "mciSendStringA"); + if (func_mciSendStringA == NULL) + return FALSE; + + char buff[255], command[100]; + + sprintf_s(command, 100, "open %s alias playsound_134", filePath); + func_mciSendStringA(command, buff, 254, NULL); + + sprintf_s(command, 100, "set playsound_134 time format milliseconds"); + func_mciSendStringA(command, buff, 254, NULL); + + sprintf_s(command, 100, "status playsound_134 length"); + func_mciSendStringA(command, buff, 254, NULL); + + sprintf_s(command, 100, "play playsound_134 from 0 to %s", buff); + func_mciSendStringA(command, buff, 254, NULL); + + return TRUE; +} + + + + + + + +int main(int a,char**b) +{ + + + for(T y=-1,s=a>1?strtod(b[1],0):1; + y<0.6;y+=0.05/s,putchar('\n')) + for(T x=-1;x<0.6;x+=0.025/s) + putchar(" .|/=\\|/=\\| @!"[(int)f(u(x,y,0.3),v(x,y,0.3))]); + + + + + + printf("\nʲôɫֺÿأ\n"); + yanse(); + int ys; + scanf("%d",&ys); + if(0==ys) SetColor(BLACK, WHITE); + else if(1==ys) SetColor(BLUE, WHITE); + else if(2==ys) SetColor(GREEN, WHITE); + else if(3==ys) SetColor(CYAN, WHITE); + else if(4==ys) SetColor(RED, WHITE); + else if(5==ys) SetColor(MAGENTA, WHITE); + else if(6==ys) SetColor(BROWN, WHITE); + else if(7==ys) SetColor(LIGHTGRAY, WHITE); + else if(8==ys) SetColor(DARKGRAY, WHITE); + else if(9==ys) SetColor(LIGHTBLUE, WHITE); + else if(10==ys) SetColor(LIGHTGREEN, WHITE); + else if(11==ys) SetColor(LIGHTCYAN, WHITE); + else if(12==ys) SetColor(LIGHTRED, WHITE); + else if(13==ys) SetColor(LIGHTMAGENTA, WHITE); + else if(14==ys) SetColor(YELLOW, BLACK); + else printf("벻Ϸ޷ɫ\n"); + // ɫ + + + + int s,z,choice; + welcome(); + scanf("%d",&z); + + + + + + + + + + + if(1==z){ + Contact con; + const char* filename = "contacts.txt"; // ļcontacts.txtɰ޸ + InitContact(&con); + Person person; + int login_result=login(&person); + if(login_result==-1){ + printf("¼ʧܣû룡\n"); + return 0; + } + // + playMusic(MID_FILE_PATH); + system("pause"); + + do + { + menu(); + scanf("%d", &s); + switch (s) + { + case 1: + if(person.user_type==1){ + ContactMember newContact; + char Name[NAME_MAX]; + char Sex[SEX_MAX]; + int Age; + char Number[TELE_MAX]; + char Address[ADDR_MAX]; + int Snumber; + printf("ϵ"); + scanf("%s",Name); + printf("ϵԱ"); + scanf("%s",Sex); + printf("ϵ䣺"); + scanf("%d",&Age); + printf("ϵ˵绰룺"); + scanf("%s",Number); + printf("ϵ˵ַ"); + scanf("%s",Address); + printf("ϵѧţ "); + scanf("%d",&Snumber); + strcpy(newContact.Name, Name); + strcpy(newContact.Sex, Sex); + newContact.Age = Age; + strcpy(newContact.Address, Address); + strcpy(newContact.Number, Number); + newContact.Snumber=Snumber; + AddContactToFile(newContact, filename); + // ٴδļȡϵϢɿ + ReadContactFromFile(&con, filename); + ReadContact(&con); + } + + else + printf("ʹ޴Ȩޣ\n"); + break; + case 2:if(person.user_type==1){ + DeleteContact(&con); + WriteContactToFile(&con, "contacts.txt"); + } + else + printf("ʹ޴Ȩޣ\n"); + break; + case 3:if(person.user_type==1) + SearchContact(&con); + else + printf("ʹ޴Ȩޣ\n"); + break; + case 4:if(person.user_type==1){ + ModifyContact(&con, "contacts.txt"); + ReadContact(&con); + } + else + printf("ʹ޴Ȩޣ\n"); + break; + case 5: + // ļȡϵϢ + ReadContactFromFile(&con, filename); + + // չʾϵϢ + ReadContact(&con); + break; + case 6:if(person.user_type==1) + ClearContacts(&con, "contacts.txt"); + else + printf("ʹ޴Ȩޣ\n"); + break; + case 7: + printf("ʽ\n1ѧ\n2\n3ѧŽ\n4\n"); + printf("ѡʽ\n"); + scanf("%d",&choice); + if(choice==1) + SortContactsBySnumber1(&con); + else if(choice==2) + SortContacts1(&con); + else if(choice==3) + SortContactsBySnumber2(&con); + else if(choice==4) + SortContacts2(&con); + else + printf("ȷѡ"); + break; + case 8:printf("ѡϲɫ\n"); + yanse(); + scanf("%d",&ys); + if(0==ys) SetColor(BLACK, WHITE); + else if(1==ys) SetColor(BLUE, WHITE); + else if(2==ys) SetColor(GREEN, WHITE); + else if(3==ys) SetColor(CYAN, WHITE); + else if(4==ys) SetColor(RED, WHITE); + else if(5==ys) SetColor(MAGENTA, WHITE); + else if(6==ys) SetColor(BROWN, WHITE); + else if(7==ys) SetColor(LIGHTGRAY, WHITE); + else if(8==ys) SetColor(DARKGRAY, WHITE); + else if(9==ys) SetColor(LIGHTBLUE, WHITE); + else if(10==ys) SetColor(LIGHTGREEN, WHITE); + else if(11==ys) SetColor(LIGHTCYAN, WHITE); + else if(12==ys) SetColor(LIGHTRED, WHITE); + else if(13==ys) SetColor(LIGHTMAGENTA, WHITE); + else if(14==ys) SetColor(YELLOW, BLACK); + else printf("벻Ϸ޷ɫ"); + break; + case 0: + saveContacts(&con); + printf("ѳɹ˳\n"); + exit(0); + break; + default: + printf("ȷѡ\n"); + } + } while (s); + loadContacts(&con); + } + else printf("ӭ´ʹã\n"); + + + return 0; +} + +//ʼԱϢ +void InitContact(Contact* con) +{ + con->sz = 0; + memset(con, 0, sizeof(con)); +} + +//ĿԱλ +int FindName(Contact* con, char* name) +{ + int i=0; + for (i = 0; i < con->sz; i++) + { + if (strcmp(con->ContactMembers[i].Name, name) == 0) + { + return i; + } + } + return -1; +} + +//С(qsortʵ) +int Sort(const void* a, const void* b) +{ + ContactMember* A = (ContactMember*)a; + ContactMember* B = (ContactMember*)b; + return memcmp(B, A, sizeof(ContactMember)); +} + +void AddContactToFile(ContactMember newContact, const char* filename) +{ + FILE* pf = fopen(filename, "a"); + if (pf == NULL) + { + perror("Open file for append failed"); + return; + } + fprintf(pf, "%s %s %d %s %s %d\n", newContact.Name, newContact.Sex, + newContact.Age, newContact.Address, newContact.Number, newContact.Snumber); + fclose(pf); +} + +void DeleteContact(Contact* con) +{ + char name[NAME_MAX]; + printf("Ҫɾϵ"); + scanf("%s", name); + int i, j; + for (i = 0; i < con->sz; i++) + { + if (strcmp(con->ContactMembers[i].Name, name) == 0) + { + // ҵ󽫺ԪǰƸҪɾԪ + for (j = i; j < con->sz - 1; j++) + { + strcpy(con->ContactMembers[j].Name, con->ContactMembers[j + 1].Name); + strcpy(con->ContactMembers[j].Sex, con->ContactMembers[j + 1].Sex); + con->ContactMembers[j].Age = con->ContactMembers[j + 1].Age; + strcpy(con->ContactMembers[j].Address, con->ContactMembers[j + 1].Address); + strcpy(con->ContactMembers[j].Number, con->ContactMembers[j + 1].Number); + con->ContactMembers[j].Snumber=con->ContactMembers[j + 1].Snumber; + } + con->sz--; + printf("ϵɾɹ\n"); + return; + } + } + printf("δҵϵˣ޷ɾ\n"); +} + +void WriteContactToFile(Contact* con, const char* filename) +{ + assert(con); + assert(filename); + int i=0; + FILE* pf = fopen(filename, "w"); + if (pf == NULL) + { + perror("Open file failed"); + return; + } + for (i = 0; i < con->sz; i++) + { + fprintf(pf, "%s %s %d %s %s %d\n", con->ContactMembers[i].Name, + con->ContactMembers[i].Sex, + con->ContactMembers[i].Age, + con->ContactMembers[i].Address, + con->ContactMembers[i].Number, + con->ContactMembers[i].Snumber); + } + fclose(pf); +} + +void SearchContact(Contact* con) +{ + assert(con); + char name[NAME_MAX]; + printf("Ҫѯˣ"); + scanf("%s", name); + int ret = FindName(con, name); + if (ret == -1) + { + printf("ѯĿ겻ڣ\n"); + return; + } + printf("%-20s\t%-5s\t%s\t%-30s\t%-12s\t%-12s\n", "", "Ա", "", "ַ", "", "ѧ"); + printf("%-20s\t%-5s\t%d\t%-30s\t%-12s\t%-12d\n", con->ContactMembers[ret].Name, + con->ContactMembers[ret].Sex, + con->ContactMembers[ret].Age, + con->ContactMembers[ret].Address, + con->ContactMembers[ret].Number, + con->ContactMembers[ret].Snumber); + +} + +void ModifyContact(Contact* con, const char* filename) +{ + char name[NAME_MAX]; + printf("Ҫ޸ĵϵ"); + scanf("%s", name); + getchar(); // 뻺ַ + int i; + for (i = 0; i < con->sz; i++) + { + if (strcmp(con->ContactMembers[i].Name, name) == 0) + { + printf("µԱ"); + fgets(con->ContactMembers[i].Sex, 5, stdin); + // ȥfgetsַĩβĻз + if (con->ContactMembers[i].Sex[strlen(con->ContactMembers[i].Sex) - 1] == '\n') + { + con->ContactMembers[i].Sex[strlen(con->ContactMembers[i].Sex) - 1] = '\0'; + } + + printf("µ䣺"); + scanf("%d", &con->ContactMembers[i].Age); + getchar(); // 뻺ַ + printf("µĵַ"); + fgets(con->ContactMembers[i].Address, ADDR_MAX, stdin); + if (con->ContactMembers[i].Address[strlen(con->ContactMembers[i].Address) - 1] == '\n') + { + con->ContactMembers[i].Address[strlen(con->ContactMembers[i].Address) - 1] = '\0'; + } + + printf("µĺ룺"); + fgets(con->ContactMembers[i].Number, TELE_MAX, stdin); + if (con->ContactMembers[i].Number[strlen(con->ContactMembers[i].Number) - 1] == '\n') + { + con->ContactMembers[i].Number[strlen(con->ContactMembers[i].Number) - 1] = '\0'; + } + + printf("µѧţ"); + scanf("%d", &con->ContactMembers[i].Snumber); + getchar(); // 뻺ַ + + printf("ϵϢ޸ijɹ\n"); + WriteContactToFile(con, filename); // ޸ĺϢдļ + return; + } + } + printf("δҵϵˣ޷޸ģ\n"); +} + +void ReadContactFromFile(Contact* con, const char* filename) +{ + assert(con); + assert(filename); + FILE* pf = fopen(filename, "r"); + if (pf == NULL) + { + perror("Open file failed"); + return; + } + con->sz = 0; + while (!feof(pf)) + { + if (fscanf(pf, "%s %s %d %s %s %d", con->ContactMembers[con->sz].Name, + con->ContactMembers[con->sz].Sex, + &(con->ContactMembers[con->sz].Age), + con->ContactMembers[con->sz].Address, + con->ContactMembers[con->sz].Number, + &(con->ContactMembers[con->sz].Snumber)) == 6) + { + con->sz++; + } + } + fclose(pf); +} + +void ReadContact(Contact* con) +{ + int i=0; + assert(con); + printf("%-20s\t%-5s\t%s\t%-30s\t%-12s\t%-12s\n", "", "Ա", "", "ַ", "", "ѧ"); + for (i = 0; i < con->sz; i++) + { + printf("%-20s\t%-5s\t%d\t%-30s\t%-12s\t%-12d\n", con->ContactMembers[i].Name, + con->ContactMembers[i].Sex, + con->ContactMembers[i].Age, + con->ContactMembers[i].Address, + con->ContactMembers[i].Number, + con->ContactMembers[i].Snumber); + + } +} + +void ClearContacts(Contact* con, const char* filename) +{ + con->sz = 0; // ͨѶ¼ЧϵΪ0 + FILE* pf = fopen(filename, "w"); // д뷽ʽļԭ + if (pf == NULL) + { + perror("Open file failed"); + return; + } + fclose(pf); + printf("ϵȫգ\n"); +} + +void SortContacts1(Contact* con) +{ + int i = 0; + int j = 0; + for (i = 0; i < con->sz - 1; i++) + { + for (j = 0; j < con->sz - i - 1; j++) + { + if (strcmp(con->ContactMembers[j].Name, con->ContactMembers[j + 1].Name) > 0) + { + // ϵ˽ṹгԱϢ + ContactMember temp = con->ContactMembers[j]; + con->ContactMembers[j] = con->ContactMembers[j + 1]; + con->ContactMembers[j + 1] = temp; + } + } + } + // дļļϵϢҲ״̬ + const char* filename = "contacts.txt"; + WriteContactToFile(con, filename); + printf("ɣ\n"); +} + +void SortContactsBySnumber1(Contact* con) +{ + int i=0,j=0; + for ( i = 0; i < con->sz - 1; i++) + { + for (j = 0; j < con->sz - i - 1; j++) + { + if (con->ContactMembers[j].Snumber>con->ContactMembers[j + 1].Snumber) + { + // ϵ˽ṹгԱϢ + ContactMember temp = con->ContactMembers[j]; + con->ContactMembers[j] = con->ContactMembers[j + 1]; + con->ContactMembers[j + 1] = temp; + } + } + } + // дļļϵϢҲ״̬ + const char* filename = "contacts.txt"; + WriteContactToFile(con, filename); + printf("ɣ\n"); +} + +void SortContacts2(Contact* con) +{ + int i = 0; + int j = 0; + for (i = 0; i < con->sz - 1; i++) + { + for (j = 0; j < con->sz - i - 1; j++) + { + if (strcmp(con->ContactMembers[j].Name, con->ContactMembers[j + 1].Name) < 0) + { + // ϵ˽ṹгԱϢ + ContactMember temp = con->ContactMembers[j]; + con->ContactMembers[j] = con->ContactMembers[j + 1]; + con->ContactMembers[j + 1] = temp; + } + } + } + // дļļϵϢҲ״̬ + const char* filename = "contacts.txt"; + WriteContactToFile(con, filename); + printf("ɣ\n"); +} + +void SortContactsBySnumber2(Contact* con) +{ + int i=0,j=0; + for ( i = 0; i < con->sz - 1; i++) + { + for (j = 0; j < con->sz - i - 1; j++) + { + if (con->ContactMembers[j].SnumberContactMembers[j + 1].Snumber) + { + // ϵ˽ṹгԱϢ + ContactMember temp = con->ContactMembers[j]; + con->ContactMembers[j] = con->ContactMembers[j + 1]; + con->ContactMembers[j + 1] = temp; + } + } + } + // дļļϵϢҲ״̬ + const char* filename = "contacts.txt"; + WriteContactToFile(con, filename); + printf("ɣ\n"); +} + +int login(Person *p) { + char input_name[20]; + char input_password[20]; + printf("û: "); + scanf("%s", input_name); + printf(": "); + scanf("%s", input_password); + + if (strcmp(input_name, ADMIN_NAME) == 0 && strcmp(input_password, ADMIN_PASSWORD) == 0) { + p->user_type = 1; + strcpy(p->info.admin.admin_name, ADMIN_NAME); + strcpy(p->info.admin.admin_password, ADMIN_PASSWORD); + return 1; + } else if (strcmp(input_name, USER_NAME) == 0 && strcmp(input_password, USER_PASSWORD) == 0) { + p->user_type = 0; + strcpy(p->info.user.user_name, USER_NAME); + strcpy(p->info.user.user_password, USER_PASSWORD); + return 0; + } + return -1; +} +void loadContacts(Contact* con) +{ + FILE *file; // һFILEָ룬ָļ + + // ļ"r"ʾֻʽ + file = fopen("contacts.txt", "r"); + int i=0; + if (file == NULL) { + // ļʧܣӡϢ˳ + perror("Error opening file"); + return ; + } + for (i = 0; i < con->sz; i++) + { + fscanf(file,"%-20s\t%-5s\t%d\t%-30s\t%-12s\t%-12d\n", con->ContactMembers[i].Name, + con->ContactMembers[i].Sex, + con->ContactMembers[i].Age, + con->ContactMembers[i].Address, + con->ContactMembers[i].Number, + con->ContactMembers[i].Snumber); + } + fclose(file); +} +void saveContacts(Contact* con) +{ + FILE *file; // һFILEָ룬ָļ + + // ļ"w"ʾֻдʽ + file = fopen("contacts.txt", "w"); + if (file == NULL) { + // ļʧܣӡϢ˳ + perror("Error opening file"); + return ; + } + int i = 0; + for (i = 0; i < con->sz; i++) + { + fprintf(file,"%-20s\t%-5s\t%d\t%-30s\t%-12s\t%-12d\n", con->ContactMembers[i].Name, + con->ContactMembers[i].Sex, + con->ContactMembers[i].Age, + con->ContactMembers[i].Address, + con->ContactMembers[i].Number, + con->ContactMembers[i].Snumber); + } + fclose(file); +}