Hello, I would like to know how do I compare two chars properly
Im making a healthcare project, its pretty rudimentary, Im trying
to make a comparison between a char that the user inputs
and the char that is in a structure that is saved in a .txt file
So far I have made two Functions for this, im using strstr to compare
but All it returns is the first input that is saved in the .txt file
doesnt matter what name I search for its always the same..:
using namespace std;
bool I_code3(const char*spr, patient &ab); //Function for search logic
void search_C_Interface();
void menu();
void saved(patient ab);
void sI_name(){
patient ac; //structure patient
char name[50]; //char for user input
bool found; //boolean for logical operations
int nopc;
cout<<" -----Search by Name------- "<<endl;
printf(" Name for Search: ");
cin>>name;
found = I_code3(name, ac); //the input is passed as argument to the function for logic
if(found == true) //If the data is found display:
{
cout<<"\n\n name: "<<ac.name<<endl;
cout<<" Blood: "<<ac.blood<<endl;
cout<<"Height: "<<ac.height<<endl;
cout<<"Social Security: "<<ac.Ssn<<endl;
}
else{ //if its not output:
cout<<" Not found "<<endl;
}
cout<<" 1.Search for Another Patient"<<endl; //other functionalities
cout<<" 2.Search with another method"<<endl;
cout<<" 3.Return to main screen"<<endl;
cin>>nopc;
switch(nopc){
case 1:
sI_name();
break;
case 2:
search_C_Interface();
break;
case 3:
menu();
}
}
bool I_code3(const char*name, patient &ab) //logic for searching
{
FILE*f; //file pointer
f=fopen("saved.txt","r"); //saved is the name of my .txt file
bool centi=false;
do {
fread(&ab,sizeof(ab),1,f);
if(!(strstr(name, ab.name))) //str to compare the input of the user with the strucure
centi=true;
}while(!(feof(f)||centi==true));
fclose(f);
if(centi==true)
return true;
else
return false;
};
I have tried it with other things like find according to age
and it works perfectly, but the age i did put it in char too
I honestly dont know anymore, if anyone could help me out
it would be of great appreciation, thanks