#include <stdio.h>
/* 要使用 fprintf() 須引入 stdio.h */
#include <conio.h>
/* 要使用 getche() 須引入 conio.h */
int main()
{
FILE *file;
file=fopen("data.txt","w");
/* 以上就是我們還沒交的 */
char name[20],sexy,birthplace[80],step;
int age,i=0;
do{
printf("請依序輸入第%2d筆資料.\n"
"姓名: ",++i);
gets(name);
printf("性別(男:m/女:f): ");
scanf("%c",&sexy);
printf("出生地: ");
getchar();
gets(birthplace);
printf("年齡: ");
scanf("%d",&age);
/* 輸入資料 */
fprintf(file,"%2d\t姓名:%s\t性別:%c\t出生地:%s\t"
"年齡:%d\n",i,name,sexy,birthplace,age);
/* 將資料存入 data.txt 中 */
printf("\n請輸入任意鍵輸入下一筆資料或按[q]結束程式\n");
getchar();
step=getche();
/* 判斷是否結束 */
} while(step!='q');
printf("\n謝謝您的使用\n"
"程式結束!!!\n");
fprintf(file,"\nDone");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.csie.ntu.edu.tw)
◆ From: 140.112.240.76
※ 編輯: shmm 來自: 140.112.240.76 (05/29 00:47)