定义一个结构体描述病患病历信息:病历号,姓名,年龄,性别,症状,初诊情况,就诊时间 (用一个结构体,存储时间:年月日)设计程序按病患姓名实现病患的查找。如果找到该病患信息,就在屏幕上显示出该人的所有信息,如果没有找到,则显示“查无此人“ 要求设计一个函数封装查找功能,并返回结构体指针 用C语言
时间: 2023-07-30 07:12:39 浏览: 211
```c
#include<stdio.h>
#include<string.h>
struct Date{
int year;
int month;
int day;
};
struct Patient{
char id[20];
char name[20];
int age;
char gender[10];
char symptom[100];
char diagnosis[100];
struct Date visit_time;
};
struct Patient* search_patient(struct Patient* patients, int num, char* name){
for(int i=0;i<num;i++){
if(strcmp(patients[i].name,name)==0){
return &patients[i];
}
}
return NULL;
}
int main(){
struct Patient patients[5]={
{"001","John",25,"Male","Fever","Cold", {2020,9,1}},
{"002","Lucy",30,"Female","Cough","Bronchitis",{2020,9,2}},
{"003","Tom",45,"Male","Headache","Migraine",{2020,9,3}},
{"004","Lily",20,"Female","Sore throat","Tonsillitis",{2020,9,4}},
{"005","Mike",55,"Male","Chest pain","Angina",{2020,9,5}}
};
char name[20];
printf("Please enter the patient name to search: ");
scanf("%s",name);
struct Patient* patient=search_patient(patients,5,name);
if(patient!=NULL){
printf("Patient ID: %s\n",patient->id);
printf("Name: %s\n",patient->name);
printf("Age: %d\n",patient->age);
printf("Gender: %s\n",patient->gender);
printf("Symptom: %s\n",patient->symptom);
printf("Diagnosis: %s\n",patient->diagnosis);
printf("Visit time: %d-%d-%d\n",patient->visit_time.year,patient->visit_time.month,patient->visit_time.day);
}else{
printf("No such patient.\n");
}
return 0;
}
```
阅读全文