Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is C. Below is my code i am still running into some errors as well i will post below (1) Create three files to

This is C. Below is my code i am still running into some errors as well i will post below

(1) Create three files to submit.

Contacts.h - Struct definition, including the data members and related function declarations

Contacts.c - Related function definitions

main.c - main() function

(2) Build the ContactNode struct per the following specifications:

Data members

char contactName[50]

char contactPhoneNum[50]

struct ContactNode* nextNodePtr

Related functions

CreateContactNode() (2 pt)

InsertContactAfter() (2 pts)

Insert a new node after node

GetNextContact() (1 pt)

Return location pointed by nextNodePtr

PrintContactNode()

Ex. of PrintContactNode() output:

Name: Roxanne Hughes Phone number: 443-555-2864 

(3) In main(), prompt the user for three contacts and output the user's input. Create three ContactNodes and use the nodes to build a linked list. (2 pts) Ex:

Person 1 Enter name: Roxanne Hughes Enter phone number: 443-555-2864 You entered: Roxanne Hughes, 443-555-2864 Person 2 Enter name: Juan Alberto Jr. Enter phone number: 410-555-9385 You entered: Juan Alberto Jr., 410-555-9385 Person 3 Enter name: Rachel Phillips Enter phone number: 310-555-6610 You entered: Rachel Phillips, 310-555-6610 

(4) Output the linked list. (2 pts) Ex:

CONTACT LIST Name: Roxanne Hughes Phone number: 443-555-2864 Name: Juan Alberto Jr. Phone number: 410-555-9385 Name: Rachel Phillips Phone number: 310-555-6610 

Code plus errors

/*Contacts.h*/

#ifndef CONTACTS_H_INCLUDED

#define CONTACTS_H_INCLUDED

struct ContactNode { char ContactName[50]; char ContactPhone[50]; struct ContactNode* nextNodePtr; };

struct ContactNode* CreateContactNode(struct ContactNode* p, char name[], char phone[]);/*create a new node*/ struct ContactNode* InsertContactAfter(struct ContactNode* p,char name[], char phone[]); /*insert a new node after node*/ struct ContactNode* GetNextContact(struct ContactNode* p); /*Return Location Pointed by nextNodePtr*/ void PrintContactNode(struct ContactNode* p); /*print a node*/

#endif // CONTACTS_H_INCLUDED

_______________________________________________________

/*Contacts.c*/

#include #include #include #include"Contacts.h"

struct ContactNode* CreateContactNode(struct ContactNode* p, char name[], char phone[])/*create a new node*/ { if((p=(struct ContactNode*)malloc(sizeof(struct ContactNode)))==NULL) { printf("Error - Could not allocate memory. Exiting... "); exit(0); } strcpy(p->ContactName,name); strcpy(p->ContactPhone,phone); p->nextNodePtr=NULL; return(p); } struct ContactNode* InsertContactAfter(struct ContactNode* p,char name[], char phone[]) /*insert a new node after node*/ { struct ContactNode* temp; if(p==NULL) /*if list is empty*/ { p=CreateContactNode(temp,name,phone); return(p); /*create and return the first node in the list*/ } else { temp=CreateContactNode(temp,name,phone); p->nextNodePtr=temp; /*create a new node and link it to the previous node in the list*/ } return(temp); } struct ContactNode* GetNextContact(struct ContactNode* p) /*Return Location Pointed by nextNodePtr*/ { return p->nextNodePtr; } void PrintContactNode(struct ContactNode* p) /*print a node*/ { printf(" Name: %s ",p->ContactName); printf("Phone Number: %s ",p->ContactPhone); }

___________________________________________________________

/*main.c*/

#include #include #include"Contacts.h" int main() { struct ContactNode* start; struct ContactNode* t; int i; char Name[50],phoneNo[50]; for(i=1;iContactName,t->ContactPhone); }

/*print the list*/ printf(" CONTACT LIST"); t=start; /*print out the list by traversing each node from start to end*/ while(t) { PrintContactNode(t); t=GetNextContact(t); } }

Current errors;

image text in transcribed

image text in transcribed

1. Unit test Tests that CreateContactNode() initializes a node with name "Jane Doe" and phone number "555-555-5555. 2. Compare output Roxanne Hughes 443-555-2864 Juan Alberto Jr. Input 410-555-9385 Rachel Phillips 310-555-6610 Person 1 Enter name: Enter phone number You entered: Roxanne Hughes 443-555-2864 Person 2 Enter name: Your output correctly starts with Enter phone number You entered: Juan Alberto Jr 410-555-9385 Person 3 Enter name: Enter phone number You entered: Rachel Phillips 310-555-6610

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

Students also viewed these Databases questions