Question: IN PROGRAMMING LANGUAGE C -This code creates a linked list I would like to know how to copy my contents from my linked list into

IN PROGRAMMING LANGUAGE C

-This code creates a linked list I would like to know how to copy my contents from my linked list into an array of characters ?

#include

#include

#include

#include

struct Node{

void *data;

struct Node *next;

};

void push(struct Node** head_ref, void *new_data, size_t data_size){

// Allocate meory for node

struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));

new_node->data = malloc(data_size);

new_node->next = (*head_ref);

int i =0;

for(i =0; i

*(char *)(new_node->data +i) = *(char *)(new_data +i);

(*head_ref) = new_node;

}

}

void printList(struct Node *node, void(*fptr) (void *)){

while(node !=NULL){

(*fptr)(node->data);

node = node->next;

}

}

void printString(void *c){

printf("%c",*(char *)c);

}

int main(int argc, char*argv[]){

struct Node *start = NULL;

int length = strlen(argv[1]);

int i =0;

int pos = -1;

for(i = length;i>=0;i--){

if(isalpha(argv[1][i])!= 0||isdigit(argv[1][i] == 0)){

push(&start,&argv[1][i],length);

}

}

printList(start,printString);

return 0;

}

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!