# 追加確認功能 追加在資料寫入文字檔前的確認 ```c= #ifndef DUTYLIFEGUARD_H_INCLUDED #define DUTYLIFEGUARD_H_INCLUDED #include <stdio.h> #include <string.h> #include "functions.h" void dutylifeguard(Member members[]) { int id1, id2, id3, id4, confirm; printf("Hired positions (sorted by number): \n"); for (int i = 0; i < MAX_MEMBERS; i++) { if (members[i].hired == 1) { printf("Number: %d, Name: %s\n", members[i].id, members[i].name); } } printf("Enter the number of the person (am): "); scanf("%d%d", &id1, &id2); printf("Enter the number of the person (pm): "); scanf("%d%d", &id3, &id4); printf("confirm?(Yes = 1/No = 0)\n"); printf("am\n%s, %s\npm\n%s, %s\n", members[id1-1].name, members[id2-1].name, members[id3-1].name, members[id4-1].name); scanf("%d", &confirm); if(confirm == 1){ FILE *fp; if ((fp = fopen ("dutylifeguard.txt", "w")) == NULL) { printf("Open File ERROR!\n"); } else{ fprintf(fp, "am\n%s, %s\npm\n%s, %s\n", members[id1-1].name, members[id2-1].name, members[id3-1].name, members[id4-1].name); fclose(fp); } } } #endif ``` ![](https://hackmd.io/_uploads/Hkl2ZYYDh.png) ```c= #ifndef ADMITTED_H_INCLUDED #define ADMITTED_H_INCLUDED #include <stdio.h> #include <string.h> void admitted(members) { int ams, pms, confirm; printf("Enter the number of the guest (am): "); scanf("%d", &ams); printf("Enter the number of the guest (pm): "); scanf("%d", &pms); printf("confirm?(Yes = 1/No = 0)\n"); printf("am\n%d\npm\n%d\nam+pm=\n%d\n", ams, pms, ams+pms); scanf("%d", &confirm); if(confirm == 1){ FILE *fp; if ((fp = fopen ("admitted.txt", "w")) == NULL) { printf("Open File ERROR!\n"); } else{ fprintf(fp, "am\n%d\npm\n%d\nam+pm=\n%d", ams, pms, ams+pms); fclose(fp); } } } #endif ``` ![](https://hackmd.io/_uploads/S1r-mKKP2.png) ```c= #ifndef POOL_H_INCLUDED #define POOL_H_INCLUDED #include <stdio.h> #include <string.h> void pool(members) { double outpH, inpH, massagepH, outppm, inppm, massageppm, outamtp, outpmtp, inamtp, inpmtp, massageamtp, massagepmtp, confirm; printf("outdoor pool pH & ppm:"); scanf("%lf %lf", &outpH, &outppm); printf("indoor pool pH & ppm:"); scanf("%lf %lf", &inpH, &inppm); printf("massage pool pH & ppm:"); scanf("%lf %lf", &massagepH, &massageppm); printf("outdoor pool am temperature(¢XC):"); scanf("%lf", &outamtp); printf("outdoor pool pm temperature(¢XC):"); scanf("%lf", &outpmtp); printf("indoor pool am temperature(¢XC):"); scanf("%lf", &inamtp); printf("indoor pool pm temperature(¢XC):"); scanf("%lf", &inpmtp); printf("massage pool am temperature(¢XC):"); scanf("%lf", &massageamtp); printf("massage pool pm temperature(¢XC):"); scanf("%lf", &massagepmtp); printf("confirm?(Yes = 1/No = 0)\n"); printf("outdoor pool\npH:%.1lf ppm:%.1lf am¢XC:%.1lf pm¢XC:%.1lf\nindoor pool\npH:%.1lf ppm:%.1lf am¢XC:%.1lf pm¢XC:%.1lf\nmassage pool\npH:%.1lf ppm:%.1lf am¢XC:%.1lf pm¢XC:%.1lf\n", outpH, outppm, outamtp, outpmtp, inpH, inppm, inamtp, inpmtp, massagepH, massageppm, massageamtp, massagepmtp); scanf("%d", &confirm); if(confirm == 1){ FILE *fp; if ((fp = fopen ("pool.txt", "w")) == NULL) { printf("Open File ERROR!\n"); } else{ fprintf(fp, "outdoor pool\npH:%.1lf ppm:%.1lf am¢XC:%.1lf pm¢XC:%.1lf\nindoor pool\npH:%.1lf ppm:%.1lf am¢XC:%.1lf pm¢XC:%.1lf\nmassage pool\npH:%.1lf ppm:%.1lf am¢XC:%.1lf pm¢XC:%.1lf\n", outpH, outppm, outamtp, outpmtp, inpH, inppm, inamtp, inpmtp, massagepH, massageppm, massageamtp, massagepmtp); fclose(fp); } } } #endif ``` ![](https://hackmd.io/_uploads/Hks34FYP3.png) ```c= #ifndef TOOL_H_INCLUDED #define TOOL_H_INCLUDED #include <stdio.h> #include <string.h> #include "functions.h" void tool(Member members[]) { int firstaidkit, lifebuoy, lifelinebag, whistle, electricfan, confirm; printf("Check Tool Status:\n"); printf("First aid kit(0 no problem/1 Need to be replaced/supplemented): "); scanf("%d", &firstaidkit); printf("life buoy(0 no problem/1 Need to be replaced/supplemented): "); scanf("%d", &lifebuoy); printf("lifeline bag(0 no problem/1 Need to be replaced/supplemented): "); scanf("%d", &lifelinebag); printf("whistle(0 no problem/1 Need to be replaced/supplemented): "); scanf("%d", &whistle); printf("electric fan(0 no problem/1 Need to be replaced/supplemented): "); scanf("%d", &electricfan); printf("confirm?(Yes = 1/No = 0)\n"); printf("Tool Status(0 no problem/1 Need to be replaced/supplemented)\nFirst aid kit:%d\nlife buoy:%d\nlifeline bag:%d\nwhistle:%d\nelectric fan:%d\n", firstaidkit, lifebuoy, lifelinebag, whistle, electricfan); scanf("%d", &confirm); if(confirm == 1){ FILE *fp; if ((fp = fopen ("tool.txt", "w")) == NULL) { printf("Open File ERROR!\n"); } else{ fprintf(fp, "Tool Status(0 no problem/1 Need to be replaced/supplemented)\nFirst aid kit:%d\nlife buoy:%d\nlifeline bag:%d\nwhistle:%d\nelectric fan:%d\n", firstaidkit, lifebuoy, lifelinebag, whistle, electricfan); fclose(fp); } } } #endif ``` ![](https://hackmd.io/_uploads/rJlJPFFP2.png)