Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me with this C programm? For this assignment you will divide up HW-10 and develop a Makefile to practice using the compiler

Can you help me with this C programm?

For this assignment you will divide up HW-10 and develop a Makefile to practice using the compiler and linker with libraries. All files will be strictly C code - no C++! Part 1 (10 points): ------------------ Seperate HW-10 into the following 4 files: 1) One file will contain all of the code/functions that build the doubly-linked linked list. Call it hw11-yourname-A.c This file will also require a header file. Call it hw11-yourname-A.h 2) One file will contain all of the code/functions that build the garbage linked list. Call it hw11-yourname-B.c This file will also require a header file. Call it hw11-yourname-B.h 3) One file will contain all of the code/functions that display the linked lists. Call it hw11-yourname-C.c This file will also require a header file. Call it hw11-yourname-C.h 4) One file will contain all of the code/functions that free the linked lists. Call it hw11-yourname-D.c This file will also require a header file. Call it hw11-yourname-D.h Write a Makefile that compiles and links the above in 2 (two) steps. You MUST call this Makefile "Makefile1". Part 2 (5 points): ------------------ Write a Makefile that creates a STATIC library/archive (hw11-lib-yourname.a) out of the associated *.c files (1, 2, 3, & 4) and that compiles and links hw11-yourname-main.c with your static library. You MUST call this Makefile "Makefile2". Part 3 (5 points): ------------------ Write a Makefile that creates SHARED a library (hw11-lib-yourname.so) out of the associated c files (1, 2, 3, & 4) and that compiles and links hw11-yourname-main.c with your shared library. You MUST call this Makefile "Makefile3". Part 4 (20 points): ------------------- Modify hw11-yourname-main.c to use the SHARED library (hw11-lib-yourname.so) dynamically (using dlopen). Call this MAIN program hw11-yourname-4.c Write a Makefile that compiles and links hw11-yourname-4.c with your dynamic shared library. You MUST call this Makefile "Makefile4". Note that all of the functionallity must exist in this program as it did in hw10 to earn full credit. 

This is my hw 10:

#include #include #include #include

struct node { int data; struct node *next; struct node *prev; };

void tooManyError() { printf("****************************************************** "); printf("Too many command line arguments given, exiting program. "); printf("****************************************************** "); }

void tooFewError() { printf("****************************************************** "); printf("Too few command line arguments given, exiting program. "); printf("****************************************************** "); }

void insertNode(struct node *item, struct node **head, struct node **tail) { if(!*head) { (*head) = item; (*head)->prev = NULL; (*tail) = item; (*tail)->next = NULL; return; } struct node *curr = *head; struct node *temp = malloc(sizeof(*temp));

while(curr->next != NULL) { curr = curr->next; }

temp = item; curr->next = temp; temp->prev = curr; (*tail) = temp; }

void DISPLAY_INORDER(struct node *head, struct node *tail) { if(head == NULL) { return; }

struct node *curr = head;

while(curr != NULL) { printf("%i ", curr->data); curr = curr->next; } }

void DISPLAY_POSTORDER(struct node *head, struct node *tail) { if(head == NULL) { return; }

struct node *curr = tail;

while(curr != NULL) { printf("%i ", curr->data); curr = curr->prev; } }

void FREE_INORDER(struct node *head, struct node *tail) { if(head == NULL) { return; }

printf(" ");

struct node *curr = head;

while(curr != NULL) { if(curr != tail) { curr = curr->next; }

if(curr != NULL && curr != tail) { free(curr->prev); }

if(curr == tail) { free(curr->prev); free(curr); break; } } }

void DELETE_NODE(int numToDelete, struct node **head, struct node **tail, struct node **trashHead, struct node **trashTail) { int i; int j; struct node *curr = malloc(sizeof(curr)); struct node *temp = malloc(sizeof(temp));

for(i = numToDelete; i > 0; i--) { int nodeToDelete = rand() % i; printf(" Deleting node at index: %i", nodeToDelete); j = 0; curr = *head;

while(curr != NULL) { if(j == nodeToDelete) { if(curr == (*head)) { if(curr->next != NULL) { (*head) = curr->next; (*head)->prev = NULL; curr->next = NULL; insertNode(curr, &*trashHead, &*trashTail); break; } else { (*head) = NULL; curr->next = NULL; insertNode(curr, &*trashHead, &*trashTail); break; } } else if(curr == (*tail)) { (*tail) = curr->prev; (*tail)->next = NULL; curr->prev = NULL; insertNode(curr, &*trashHead, &*trashTail); break; } else { temp = curr->prev; temp->next = curr->next; temp = curr->next; temp->prev = curr->prev; curr->prev = NULL; curr->next = NULL; insertNode(curr, &*trashHead, &*trashTail); break; } } j++; curr = curr->next; } } }

void DISPLAY_TRASH(struct node *head, struct node *tail) { printf(" Trash Inorder: "); DISPLAY_INORDER(head, tail); printf(" Trash Postorder: "); DISPLAY_POSTORDER(head, tail);

FREE_INORDER(head, tail); }

int main(int argv, char **argc) { if(argv > 2) { tooManyError(); return 0; } if(argv < 2) { tooFewError(); return 0; }

int n = atoi(argc[1]); int i; struct node *head = NULL; struct node *tail = NULL; struct node *trashHead = NULL; struct node *trashTail = NULL;

for(i = 0; i <= n; i++) { struct node *item = malloc(sizeof(*item)); item->data = i; item->next = NULL; item->prev = NULL;

insertNode(item, &head, &tail); printf("Input data: %i\t\t ", i); }

srand(time(NULL)); int numToDelete = rand() % (atoi(argc[1]) + 2); printf(" Deleting %i node(s)... ", numToDelete);

DELETE_NODE(numToDelete, &head, &tail, &trashHead, &trashTail);

if(trashHead != NULL) { DISPLAY_TRASH(trashHead, trashTail); }

printf(" Inorder: "); DISPLAY_INORDER(head, tail); printf(" Postorder: "); DISPLAY_POSTORDER(head, tail); printf(" ");

FREE_INORDER(head, tail); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions