Try   HackMD

輸出txt轉輸出excel

因為比起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

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
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

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

所以換成舊版(xls)

問題

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

會報錯但可以正常使用