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
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