#include <stdio.h>
#include <stdlib.h>
struct patients{
char last_name[15];
int passport_number;
char disease[30];
char doctors_last_name[15];
};
int main (){
int n,i;
char enter_doctors_last_name [15];
struct patients mas_struct[3]={{"Ivanov",5457401,"COVID-18","Davis"},{"Petrov",2864228,"COVID-19","Davis"},{"Petrova",63863380,"COVID-19","Dixon"}};
printf("\nPatients:");
printf("\n Last name | Passport number | \tDisease | Doctor's last name ");
for (i=0;i<3;i++)
printf("\n %s \t%d \t%s \t%s",mas_struct[i].last_name,mas_struct[i].passport_number,mas_struct[i].disease,mas_struct[i].doctors_last_name);
printf("\n");
printf("\nEnter doctor's last name:");
scanf("%s", enter_doctors_last_name);
printf("\nPatients:");
for (i=0;i<3;i++)
if(mas_struct[i].doctors_last_name == enter_doctors_last_name)
printf("\n %s \t%d \t%s \t%s",mas_struct[i].last_name,mas_struct[i].passport_number,mas_struct[i].disease,mas_struct[i].doctors_last_name);
return 0;
}
比较字符时遇到麻烦,它不起作用,我无法提出正确的词来进行谷歌搜索。
在我键入“ Davis”或“ Dixon”的最后一行时,enter_doctors_last_name
输出只是病人
我也尝试使用gets
函数##
您无法使用==
运算符比较字符串,而应使用strcmp
:
您应该使用strcmp()
函数比较字符串。