Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! I am stuck! The instructions is below my code. #include #include #include #define BUFFSIZE 100 Nodeptr newNode; struct node_struct { char *myString; struct

Please help! I am stuck!

The instructions is below my code.

#include

#include

#include

#define BUFFSIZE 100

Nodeptr newNode;

struct node_struct

{

char *myString;

struct node_struct *next;

};

typedef struct node_struct Node;

typedef Node *Nodeptr;

void addString(Nodeptr head, char * newStr, char * aString) {

char BUFFER[BUFFSIZE];

printf(" Enter a string: ");

newNode = (Nodeptr)malloc(sizeof(Node));

strcpy(newStr, aString);

newNode->myString = newString;

Node Ptr currPtr = head;

Node Ptr lastPtr = NULL;

int finished = 0;

while ((currPtr != NULL) && (!finished)) {

if (strcmp(currPtr->myString, aString) > 0) {

currPtr->next = new Node;

new Node-> = currePtr;

finished = 1;

}

else {

lastPtr = currPtr;

currPtr = currPtr->next;

}

}

return head;

}

void modifyString()

int main()

{

int _choice = 0;

struct node_struct *head = NULL;

do

{

printf(" Main Menu: ");

printf("1. Add string. ");

printf("2. Modify string. ");

printf("3. Delete string. ");

printf("4. List the strings. ");

printf("5 Quit. ");

printf("Please enter your choice : ");

scanf("%d", &_choice);

switch (_choice) {

case 1:

head = addString(head);

break;

case 2:

head = modifyString(head);

break;

case 3:

head = deleteString(head);

break;

case 4:

listStrings(head);

break;

case 5:

break;

default:

printf(" Wrong choice. Try again. ");

break;

}

} while (_choice != 5);

return 0;

}

Assignment:

Using C, Write a program that manages a linked list of records stored in structs.

1) You must use typedef. This is one of the main points of using linked list.

2) Structs cannot store the string in a fixed length array. This is not reconmended fo this project.

3) The strings has to be sorted out in alphabetical order. You could sort strings by ordering the *pointers* without copying the strings anywhere. This saves on storage and has improved performance as well.

A rough example should look like the program below:

Please be sure to use "typedef".

typedef struct node{

char *myString;

struct node* next;

}

Each "node" will manage a string, and a pointer to the next node in the list.

Once youve removed a node from the list, you need to return the memory (using free()), or youll have a leak.

Cook up a menu like so:

void main_menu()

{

char char_choice[3];

int int_choice = 0;

do

{

printf(" ");

printf("Main Menu: ");

printf("1. XXX ");

printf("2. YYY ");

printf("3. Etc... ");

scanf("%s", char_choice);

int_choice = atoi(char_choice);

switch (int_choice)

{

case 1:

function_XXX();

break;

case 2:

function_YYY();

break;

case 3:

function_Etc();

break;

default:printf("Wrong choice. Enter Again");

break;

}

}while(int_choice !=99);

}

The menu should allow you to add a string, modify a string, delete a string, list the strings, or quit.

This will give you enough practice with linked list.

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

Step: 3

blur-text-image

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

1. What might have led to the misinformation?

Answered: 1 week ago

Question

2. How will you handle the situation?

Answered: 1 week ago