※ [本文轉錄自 ESOE-91 看板]
作者: shmm (靜力靜力靜力靜力靜力) 看板: ESOE-91
標題: 上一次繼承
時間: Wed Jun 11 01:01:53 2003
我稅到剛剛 這麼晚po 對不起
以嚇
#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;
}
------------------------------------------------
#include <stdio.h>
/* 要使用 fprintf() 須引入 stdio.h */
#include <string.h>
/* 要使用 strcmp() 須引入 string.h */
int main()
{
FILE *file;
file=fopen("data.txt","r");
int i=0;
char buffer[20];
do{
if(i++%5==0)
printf("\n");
fscanf(file,"%s",buffer);
printf("%s\t",buffer);
}while(strcmp(buffer,"Done")!=0);
printf("\n\n");
return 0;
}
--------------------------------------------------------
#include <stdio.h>
#include <string.h>
int main()
{
FILE *file;
file=fopen("data.txt","r");
int i,j=0;
char keyword[20],search[20];
printf("請輸入您要查詢的姓名: ");
gets(keyword);
do{
fscanf(file,"%s",search);
if(strcmp(keyword,search)==0)
{
for(i=0,j=1;i<4;i++)
{
printf("%s\t",search);
fscanf(file,"%s",search);
}
printf("\n");
}
}while(strcmp(search,"Done")==0);
if(j==0) printf("查無此人 XD\n");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.csie.ntu.edu.tw)
◆ From: 140.112.240.76
--
※ 發信站: 批踢踢實業坊(ptt.csie.ntu.edu.tw)
◆ From: 140.112.26.85