why this code is not working with me Programming code in C

why this code is not working with me?

Programming code in C ***************** must be C ***** Using Xcode******

-------------------------------------------------------

#include<stdio.h>
#include<curses.h>
#include <stdlib.h>
//-------------------------------------------------

int getche(void);
struct node
{
int pid;
char fname[10];
char sname[10];
struct node *next;
};
//------------------------------------------------------------
struct node *start=NULL;
struct node *create(struct node *);
struct node *display(struct node*);
struct node *sort(struct node*);

struct node *create(struct node *start)
{
struct node *new_node ,*ptr;
char ch;
do
{
  
new_node=(struct node *)malloc(sizeof(struct node));
  
printf(\"Enter Patient ID: \");
scanf(\"%d\",&new_node->pid);
printf(\"Enter Patient First name: \");
scanf(\"%s\",new_node->fname);
printf(\"Enter Patient family name: \");
scanf(\"%s\",new_node->sname);
new_node->next=NULL;
  
if(start==NULL)
{
new_node->next=NULL;
start=new_node;
}
else
{
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=NULL;
}
  
printf(\"\ Do you want to create another : \");
ch=getche();
}while(ch!=\'n\');
return start;
}
//------------------------------------------------------------------

struct node* display(struct node* start)
{
struct node *new_node;
printf(\"\ The Linked List : \");
new_node=start;
while(new_node!=NULL){
printf(\"\ %d\",new_node->pid);
printf(\"\\t %s\", new_node->fname);
printf(\"\\t %s\",new_node->sname);
new_node=new_node->next;
}
return start;
}

struct node* sort(struct node* start){
struct node *ptr1,*ptr2;
char temp[10];
int i;
while(ptr1->next!=NULL){
ptr2=ptr1->next;
while(ptr2!=NULL){
if(ptr1->sname[0]>ptr2->sname[0]){
for (i=0;i<2;i++)
temp[i]=ptr1->sname[i];
for (i=0;i<2;i++)
ptr1->sname[i]=ptr2->sname[i];
for (i=0;i<2;i++)
ptr2->sname[i]=temp[i];
}
ptr2=ptr2->next;
}
ptr1=ptr1->next;
}
return start;
}


//----------------------------------------------------
int main()
{
start=create(start);
start=sort(start);
start=display(start);
getch();
}


=============

loops requesting information about patients and inserting the information into a linked list:

call a function responsible for allocating the memory for the new item, requesting the following information for each patient: first name, last name, and patientid (an integer), and putting the information into the new item

the function mentioned in part a should return a pointer to the new item

call a function to insert the new item into the linked list

new patients should be added so that the list is in alphabetical order by the last name

leave the loop when the patient id is set to 0

displays the patient information in alphabetical order by the last name once all data has been provided. The first and last name and patient id for each patient should be displayed

After the data has been input and displayed, enter another loop that asks for a patient’s last name and then displays the information for that patient:

Write a function to search for the patient in the linked list and return a pointer to the item if it is found. If it is not found return null

If the patient is found, display the patient’s full name and id number.

If the patient is not found, display a message saying the patient was not found.

Leave the loop if the person enters a zero for the person’s last name.

Solution

struct node* display(struct node* start)
{
struct node *new_node;
printf(\"\ The Linked List : \");
new_node=start;
while(new_node!=NULL){
printf(\"\ %d\",new_node->pid);
printf(\"\\t %s\", new_node->fname);
printf(\"\\t %s\",new_node->sname);
new_node=new_node->next;
}
return start;
}

struct node* sort(struct node* start){
struct node *ptr1,*ptr2;
char temp[10];
int i;
while(ptr1->next!=NULL){
ptr2=ptr1->next;
while(ptr2!=NULL){
if(ptr1->sname[0]>ptr2->sname[0]){
for (i=0;i<2;i++)
temp[i]=ptr1->sname[i];
for (i=0;i<2;i++)
ptr1->sname[i]=ptr2->sname[i];
for (i=0;i<2;i++)
ptr2->sname[i]=temp[i];
}
ptr2=ptr2->next;
}
ptr1=ptr1->next;
}
return start;
}


//----------------------------------------------------
int main()
{
start=create(start);
start=sort(start);
start=display(start);
getch();
}

why this code is not working with me? Programming code in C ***************** must be C ***** Using Xcode****** ------------------------------------------------
why this code is not working with me? Programming code in C ***************** must be C ***** Using Xcode****** ------------------------------------------------
why this code is not working with me? Programming code in C ***************** must be C ***** Using Xcode****** ------------------------------------------------

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site