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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started