作者shmm (有要念书找找我)
看板ESOE-91
标题计程实习回顾1
时间Sun Jun 15 23:09:11 2003
※ [本文转录自 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