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

This is one.c: #include<stdio.h> #include<stdlib.h> typedef struct letter{ char

ID: 3806601 • 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

Hi Student,

Your one.c program is wrong. To get the output DIRTYROOM, you should not re initialize the variables. You just need to adjust the pointers ( it is clearly mentioned in the question). I know this becasue, I have read your first queston before. I have written the correct program for one.c. Please find below.

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.next =&e;
b.next =&d;
c.next =&f;
d.next =NULL;
e.next =&c;
f.next =&i;
g.next =&b;
h.next =&g;
i.next =&h;

Letter *ptr1 = &a;
while(ptr1!=NULL){
printf("%c",ptr1->ch);
ptr1=ptr1->next;
}
printf(" ");
return 0;
}

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