Question: CONVERT THE FOLLOWING CODE FROM LINKED LIST TO ARRAY OF STRUCT #include #include shell.h #include #include #include interpreter.h int set( char *words[]); int print( char

CONVERT THE FOLLOWING CODE FROM LINKED LIST TO ARRAY OF STRUCT

#include

#include "shell.h"

#include

#include

#include "interpreter.h"

int set(char *words[]);

int print(char *words[]);

int run(char *words[]);

struct shellMem{

char *var;

char *value;

struct shellMem *next;

}*head=NULL;

int set(char *words[]){

struct shellMem *temp = head;

int flag = 0;

if(head == NULL){

head = malloc(sizeof(struct shellMem));

head->value = strdup(words[2]);

head->var = strdup(words[1]);

head->next = NULL;

}else{

while(temp != NULL){

if (strcmp(temp->var,(words[1]))==0){

temp->value = strdup(words[2]);

int flag = 1;

break;

}else temp = temp->next;

}

if(flag == 0){

temp = head;

while(temp->next!=NULL) temp=temp->next;

temp->next = malloc(sizeof(struct shellMem));

temp->next->value = strdup(words[2]);

temp->next->var = strdup(words[1]);

temp->next->next = NULL;

}

}

return 0;

}

int print(char *words[]){

int flag = 0;

struct shellMem *temp = head;

if(temp == NULL) printf("Variable does not exist. ");

while(temp!=NULL){

if (strcmp(temp->var,(words[1]))==0) {

printf("%s ",temp->value);

flag = 1;

break;

} else temp=temp->next;

}

if(flag == 0) {

printf("Variable does not exist. ");

}

return 0;

}

***** HEADER FILE shellmemory.h******

int set(char *words[]);

int print(char *words[]);

int run(char *words[]);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!