因為比起txt文字檔excel表格更容易看,我嘗試換成excel
#ifndef HIREPERSON_H_INCLUDED
#define HIREPERSON_H_INCLUDED
#include <stdio.h>
#include <string.h>
#include "functions.h"
void hirePerson(Member members[]) {
int id;
char name[80];
printf("Enter the number of the person you want to hire: ");
scanf("%d", &id);
getchar();
printf("Enter the name of the person you want to hire: ");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = 0;
for (int i = 0; i < MAX_MEMBERS; i++) {
if (members[i].id == id) {
members[i].hired = 1;
strcpy(members[i].name, name);
break;
}
}
FILE *fp;
if ((fp = fopen ("hirelist.xls", "w")) == NULL) {
printf("Open File ERROR!\n");
}
else{
fprintf(fp, "編號\t是否已招募\t姓名\n");
for (int i = 0; i < MAX_MEMBERS; i++) {
fprintf(fp, "%d\t%d\t%s\n", members[i].id, members[i].hired, members[i].name);
}
fclose(fp);
}
}
#endif
Learn More →
新版(xlsx)檔案無法使用
#ifndef HIREPERSON_H_INCLUDED
#define HIREPERSON_H_INCLUDED
#include <stdio.h>
#include <string.h>
#include "functions.h"
void hirePerson(Member members[]) {
int id;
char name[80];
printf("Enter the number of the person you want to hire: ");
scanf("%d", &id);
getchar();
printf("Enter the name of the person you want to hire: ");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = 0;
for (int i = 0; i < MAX_MEMBERS; i++) {
if (members[i].id == id) {
members[i].hired = 1;
strcpy(members[i].name, name);
break;
}
}
FILE *fp;
if ((fp = fopen ("hirelist.xlsx", "w")) == NULL) {
printf("Open File ERROR!\n");
}
else{
fprintf(fp, "編號\t是否已招募\t姓名\n");
for (int i = 0; i < MAX_MEMBERS; i++) {
fprintf(fp, "%d\t%d\t%s\n", members[i].id, members[i].hired, members[i].name);
}
fclose(fp);
}
}
#endif
Learn More →
所以換成舊版(xls)
Learn More →
會報錯但可以正常使用
今日當值救生員 #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");
Jun 17, 2023追加在資料寫入文字檔前的確認 #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;
Jun 17, 2023仿照前面的代碼寫物資狀態 #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;
Jun 17, 2023仿照前面的代碼寫泳池狀態 #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; printf("outdoor pool pH & ppm:");
Jun 17, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up