求高手大哥指教!!小弟感激不尽!!!
我想将num按数字顺序1,2,3.4输入到病人信息.txt中,再显示出来!!include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
struct patient{
int num;
int flag;
char name[20];
int subject;
};
struct patient *guahao();
void main()
{
int size = sizeof(struct patient);
int flag=1;
guahao();
}
struct patient *guahao()
{
struct patient *p;
FILE *fp;char ch;
int num=0;
int flag;
int size = sizeof(struct patient);
char name[20];
int subject;
int n;
printf("挂号请按0:");
scanf("%d",&flag);
printf("请输入你的名字:");
scanf("%s",name);
printf("请输入你要看的科目:");
scanf("%d",&subject);
if((fp=fopen("E:\\病人信息.txt","ab+"))==NULL){
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
p= (struct patient *)malloc(size);
strcpy(p->name,name);
p->subject=subject;
p->flag=flag;
fwrite(p,sizeof(struct patient),1,fp);
n=ftell(fp);
fseek(fp,n,SEEK_SET);
fread(p,sizeof(struct patient),1,fp);
printf("你名字是:%s你选的科目是:%d\n",p->name,p->subject);
if(flag==0){
printf("你正在等待中\n");
num++;
}
p->num=num;
printf("你的号数是:%d",num);
fclose(fp);
return 0;
}