Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have been trying all day to find a way to search in a link listfor matching pa

ID: 3612946 • Letter: I

Question

I have been trying all day to find a way to search in a link listfor matching patient id, and if i find the matching input, i wantto break from the link list but i'm not able to get it so pleasehelp.

This is the last three functions it link to the problem. Thefunction "matchpatient" is the one im doing the search.
Below is the example of the text file
lastname firstname age id:

Pete Okay 45   345
Maud Okay 36 536
Caleb Dimitri 15 123
Cadrin Christopher 9 695
void addnewnode(FILE *notefile, struct patient *nextpatient, structclinic *xhosp)
{


        struct patient*cur_patient;

        while(fscanf(notefile,"%s %s %d %lf", nextpatient->firstname,nextpatient->lastname, &(nextpatient->id),&(nextpatient->savingacct)) != EOF)
        {
               if(!xhosp->patnodes)
               {
                       xhosp->patnodes =nextpatient;                                         //first patient added
               }
               else
               {
                       cur_patient->link = nextpatient;
               }
                       cur_patient = nextpatient;
                       nextpatient = (struct patient *) malloc(1 * sizeof(structpatient));
                       nextpatient->link = NULL;
        }
        free(nextpatient);

}
void printlist(struct clinic *xhosp, struct patient *checkpats)
{
        struct patient*cur_patient;
       if(!xhosp->patnodes)
        {
               printf("No patients. ");
               return;
        }
        cur_patient =xhosp->patnodes;

        printf(" Below arethe information of the patients. ----------------------------------------- ");

        while(cur_patient)
        {
               //printpatient(cur_patient);

               markpatient(cur_patient, checkpats);
               cur_patient = cur_patient->link;
        }
}
void markpatient(struct patient *allpatients, struct patient*checkpatient)
{
        int index;
        //printf("X The value ofcheckpatient id is %d ", checkpatient->id);

        printf(" Forsecurity purposes please enter your id ");
        scanf("%d",&(checkpatient->id));

        if(allpatients->id ==checkpatient->id)
        {
            checkpatient = allpatients;

            "CHECKPATS" HAS NO VALUE SO I WANT TO MATCH THE "ID" STORED IN THELINKLIST TO THE INPUT "ID" IF I FOUND IT THEN I WANT TO TERMINATETHE SEARCH AND THAT NODE WILL BE STORE IN "CHECKPATIENT" SO I CANUSE IT IN A DIFFERENT FUNCTIONS. THANK YOU FOR YOUR HELP.
            return;
        }

}


Explanation / Answer

I've written an example how to go over all your patients and removeall the patients with a specific id, you can use this to iteratethrough all your patients for other purposes... // this will remove all patients with a specific id void remove_id(struct clinic *i_clinic_p, int i_id) {     struct patient *prev_patient;     struct patient *cur_patient;     prev_patient = i_clinic_p->patients_list;     // handle first node     while (prev_patient &&prev_patient->id == i_id) { // note, dirty code style here,&& is evaluates by the order written (prev_patientcondition must be writter first not to get a run-time error (youcan also seperate the conditions)         i_clinic_p->patients_list= prev_patient->link;         free(prev_patient);         prev_patient =i_clinic_p->patients_list;     } // while     if (!prev_patient) { // no patients         return;     }     // handle rest of list     cur_patient = prev_patient->link;     while (cur_patient) {         while (cur_patient &&cur_patient->id == i_id) { // remove it            prev_patient->link = cur_patient->link;            free(cur_patient);            cur_patient = prev_patient->link;         } // while         if (cur_patient) {            prev_patient = cur_patient;            cur_patient = cur_patient->link;         } // if     } // while } // void remove_id()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote