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

tutors name is prince and my name is tauseef. PAVE TP 1 2017 uigity of Technolog

ID: 3867091 • Letter: T

Question


tutors name is prince and my name is tauseef.

PAVE TP 1 2017 uigity of Technology COs1000 Developing Technical Softwa 5. Write C commands struct friend char name [20]; struct node *next; d; typedef struct friend FRIEND; typedef FRIEND FRIENDPtr FRIENDPtr startptr; Peter Zen NULL o nodes in order into the linked list shown above. One node shoul your tutor's first name (ask the tutor ify startptr contain your first name and another node should contain don't know your tutor's name). Declar pointers as required. e necessary

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>

struct friend {
      char name[20];
      struct friend *next;
};

typedef struct friend FRIEND;
typedef FRIEND * FRIENDPtr;

int main(){

   FRIENDPtr startptr,ptr,ptr1;
   startptr = (FRIENDPtr)malloc(sizeof(FRIEND));
     
   startptr->name[0] ='P';
   startptr->name[1] ='e';
   startptr->name[2] ='t';
   startptr->name[3] ='e';
   startptr->name[4] ='r';
  
   startptr->next = (FRIENDPtr)malloc(sizeof(FRIEND));
   ptr = startptr->next;
   ptr->name[0] = 'Z';
   ptr->name[1] = 'e';
   ptr->name[2] = 'n';
   ptr->next = NULL;
   ptr1 = ptr;
  
   ptr = startptr;
   ptr->next = (FRIENDPtr)malloc(sizeof(FRIEND));
   ptr = ptr->next;
   ptr->name[0] ='P';
   ptr->name[1] ='r';
   ptr->name[2] ='i';
   ptr->name[3] ='n';
   ptr->name[4] ='c';
   ptr->name[5] ='e';

   ptr->next = (FRIENDPtr)malloc(sizeof(FRIEND));
   ptr = ptr->next;
   ptr->name[0] ='T';
   ptr->name[1] ='a';
   ptr->name[2] ='u';
   ptr->name[3] ='s';
   ptr->name[4] ='e';
   ptr->name[5] ='e';
   ptr->name[6] ='f';
   ptr->next = ptr1;

   ptr = startptr;
   while (ptr != NULL){
        printf("%s ",ptr->name);
        ptr = ptr->next;
   }
   printf(" ");
   return 0;
}