数据结构和患者记录

时间:2015-10-18 06:21:05

标签: c data-structures

计算机化健康记录可以使患者更容易在各种医疗保健专业人员之间分享他们的健康状况和历史记录。健康诊所需要您的帮助来使患者计算机化。健康记录。患者的记录包括名字,中间名,姓(包括SR,JR等),性别,出生日期,身高(以英寸为单位),体重(以磅为单位)。该诊所需要该计划的以下功能:

  1. 从文件中读取现有记录,其中每个患者记录是用逗号分隔每个数据的一行条目
  2. 将其他记录添加到文件
  3. 计算并返回3岁以上患者的功能
  4. 使用给定公式计算体重指数的函数BMI =(磅重X 703)/(英寸高度X 2)或BMI =(体重重量)/(身高) -meter X 2)
  5. 搜索患者姓名并显示患者年龄和BMI值(包括类别)的信息
  6. 更新患者出生日期,身高和/或体重的信息并保存文件更新
  7. 以表格格式显示所有记录
  8. 到目前为止,我所做的是:

    #include<stdio.h>
    #include<stdlib.h>
    
    main(){
    FILE*fin;
    char name,fname,mname,lname,ename,gender,ch,getch,patient;
    int dob,month,day,year,height,weight;
    fin=fopen("oldrec.c","w");{
    printf("Error: File does not exists");
    return 0;
    }
    {
    printf("Add Record? y/n");
    ch=toupper(getch);
    if(ch='y')
    break;
    }while (1);
    
    struct patient{
    char name;
    char fname[20];
    char mname[20];
    char lname[20];
    char gender;
    int dob;
    int month;
    int day;
    int year;
    int height;
    int weight;
    
    printf("/n Patient's Name");
    printf("First Name: ");
    scanf("%s", &patient.fname);
    printf("Middle Name: ");
    scanf("%s", &patient.mname);
    printf("Last Name: ");
    scanf("%s", &patient.lname);
    printf("Gender: ");
    scanf("%s", &patient.gender);
    printf("Date of Birth");
    printf("Month: ");
    scanf("&d", &patient.month);
    printf("Day: ");
    scanf("&d", &patient.day);
    printf("Year: ");
    scanf("%s", %patient.year);
    printf("Height: ");
    scanf("%d", & patient.height);
    printf("Weight: ");
    scanf("%d", &patient.weight);
    
    }
    

    我已经制作了另一个文件,但是当我运行代码时,它会显示&#34;错误:文件不存在&#34;。有什么问题,其他问题的代码是什么?请帮我!这是我对数据结构主题的最终要求。

1 个答案:

答案 0 :(得分:2)

fin=fopen("oldrec.c","w");{              // no if 
   printf("Error: File does not exists");      // all statements will be executed 
   return 0;                   // and function will terminate here
}

当然它会显示消息,没有条件。无论fopen是否成功而没有if,所有语句都将被执行。

将其置于具有条件的if块中。

像这样写 -

fin=fopen("oldrec.c","w");             
if(fin==NULL){                  // check if fin is NULL 
     printf("Error: File does not exists");
     return 0;
}

其他问题是这些陈述 -

scanf("%s", &patient.fname);
...
scanf("%s", &patient.mname);
...
scanf("%s", &patient.lname);
...     
scanf("%s", &patient.gender);      // use %c for reading char variable 
...
scanf("%s", %patient.year);        // use %d to read int 
            ^ whats this 

像这样写这些状态 -

scanf("%s", patient.fname);
...
scanf("%s", patient.mname);
...
scanf("%s", patient.lname);
...     
scanf("%c", &patient.gender);       
...
scanf("%d", &patient.year);