complete the program C language typedef struct leter { char info; struct letter
ID: 3607602 • Letter: C
Question
complete the program C language
typedef struct leter {
char info;
struct letter *next;
} Letter;
int main (void) {
Letter a, b, c, d, e, f, g, h, i, j, k, l, m;
a.info = 'E'; a.next = &b;
b.info = 'L'; b.next = &c;
c.info = 'E'; c.next = &d;
d.info = 'V'; d.next = &e;
e.info = 'E'; e.next = &f;
f.info = 'N' ; f.next = &g;
g.info = 'P': g.next = &h;
h.info = 'L'; h.next = &i;
i.info = 'U'; i.next = &j;
j.info = 'S'; j.next = &k;
k.info = 'T'; k.next = &l;
l.info = 'W'; l.next = &m;
m.info = 'O'; m.next = NULL;
Letter *ptr = &a;
while (ptr != NULL) {
printf("%c", ptr->info);
ptr = ptr->next;
}
printf(" ");
// rearrange pointers so that it spells "TWELVEPLUSONE"
// You cannot change any of the "info" values in any Letter
//After rearranging print the new word
ptr = &k;
while (ptr != NULL) {
printf("%c", ptr->info);
ptr = ptr->next;
}
printf(" ");
return 0;
}
Explanation / Answer
Hello,
the changes in the code that you had requested is as follows.
Refer to my comment in the code "//Pointer changes to reflect "TWELVEPLUSONE""
If the code helps you, please do not forget to rate the answer.
Output
=============
sandbox ./a.out
ELEVENPLUSTWO
TWELVEPLUSONE
// =========================== Code ============================================
#include <stdio.h>
typedef struct leter
{
char info;
struct letter *next;
} Letter;
int main(void)
{
Letter a, b, c, d, e, f, g, h, i, j, k, l, m;
a.info = 'E';
a.next = &b;
b.info = 'L';
b.next = &c;
c.info = 'E';
c.next = &d;
d.info = 'V';
d.next = &e;
e.info = 'E';
e.next = &f;
f.info = 'N';
f.next = &g;
g.info = 'P';
g.next = &h;
h.info = 'L';
h.next = &i;
i.info = 'U';
i.next = &j;
j.info = 'S';
j.next = &k;
k.info = 'T';
k.next = &l;
l.info = 'W';
l.next = &m;
m.info = 'O';
m.next = NULL;
Letter *ptr = &a;
while (ptr != NULL)
{
printf("%c", ptr->info);
ptr = ptr->next;
}
printf(" ");
// rearrange pointers so that it spells "TWELVEPLUSONE"
// You cannot change any of the "info" values in any Letter
//After rearranging print the new word
ptr = &k;
//Pointer changes to reflect "TWELVEPLUSONE"
l.next = &c;
c.next = &b;
b.next = &d;
e.next = &g;
j.next = &m;
m.next = &f;
f.next = &a;
a.next = NULL;
while (ptr != NULL)
{
printf("%c", ptr->info);
ptr = ptr->next;
}
printf(" ");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.