This is one.c: #include<stdio.h> #include<stdlib.h> typedef struct letter{ char
ID: 3806602 • Letter: T
Question
This is one.c:
#include<stdio.h>
#include<stdlib.h>
typedef struct letter{
char ch;
struct letter *next;
} Letter;
int main(){
Letter a,b,c,d,e,f,g,h,i;
a.ch='D'; a.next =&b;
b.ch='O'; b.next =&c;
c.ch='R'; c.next =&d;
d.ch='M'; d.next =&e;
e.ch='I'; e.next =&f;
f.ch='T'; f.next =&g;
g.ch='O'; g.next =&h;
h.ch='R'; h.next =&i;
i.ch='Y'; i.next =NULL;
Letter *ptr = &a;
while(ptr!=NULL){
printf("%c",ptr->ch);
ptr=ptr->next;
}
printf(" ");
a.ch='D'; a.next =&b;
b.ch='I'; b.next =&c;
c.ch='R'; c.next =&d;
d.ch='T'; d.next =&e;
e.ch='Y'; e.next =&f;
f.ch='R'; f.next =&g;
g.ch='O'; g.next =&h;
h.ch='O'; h.next =&i;
i.ch='M'; i.next =NULL;
Letter *ptr1 = &a;
while(ptr1!=NULL){
printf("%c",ptr1->ch);
ptr1=ptr1->next;
}
printf(" ");
return 0;
}
2. Name this program two C In your one c program, replace the line shown in blue below with the line shown in red. Modify the rest of your program including insertion of the necessary malloc statements so that your program runs the same as your one.c program runs. Letter a, b, c, d, e, f, g, h, i Letter *a, *b *c, *d *e, *f *g *h,Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
typedef struct letter{
char ch;
struct letter *next;
}Letter;
int main(void)
{
Letter *a,*b,*c,*d,*e,*f,*g,*h,*i;
a = (Letter*)malloc(sizeof(Letter));
b = (Letter*)malloc(sizeof(Letter));
c = (Letter*)malloc(sizeof(Letter));
d = (Letter*)malloc(sizeof(Letter));
e = (Letter*)malloc(sizeof(Letter));
f = (Letter*)malloc(sizeof(Letter));
g = (Letter*)malloc(sizeof(Letter));
h = (Letter*)malloc(sizeof(Letter));
i = (Letter*)malloc(sizeof(Letter));
a->ch='D';a->next=b;
b->ch = 'O'; b->next = c;
c->ch = 'R'; c->next = d;
d->ch = 'M'; d->next = e;
e->ch = 'I'; e->next = f;
f->ch = 'T'; f->next = g;
g->ch = 'O'; g->next=h;
h->ch = 'R'; h->next = i;
i->ch = 'Y'; i->next = NULL;
Letter *ptr = a;
while (ptr!=NULL)
{
printf("%c",ptr->ch);
ptr = ptr->next;
}
printf(" ");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.