Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is C I am not sure on why I am getting these remaining two error any help w

ID: 3804975 • Letter: T

Question

This is C I am not sure on why I am getting these remaining two error any help would be appericated.

Current errors;

My Code

Contacts.C

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include"Contacts.h"

struct ContactNode* CreateContactNode(struct ContactNode* p, char name[], char phone[]){

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[]){

struct ContactNode* temp;

if(p==NULL){

p=CreateContactNode(temp,name,phone);

return(p);

}

  

else{

temp=CreateContactNode(temp,name,phone);

p->nextNodePtr=temp;

}

return(temp);

}

struct ContactNode* GetNextContact(struct ContactNode* p) {

return p->nextNodePtr;

}

void PrintContactNode(struct ContactNode* p) {

printf(" Name: %s ",p->ContactName);

printf("Phone number: %s ",p->ContactPhone);

}


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[]);

struct ContactNode* InsertContactAfter(struct ContactNode* p,char name[], char phone[]);

struct ContactNode* GetNextContact(struct ContactNode* p);

void PrintContactNode(struct ContactNode* p);

#endif


Main.c

#include <stdio.h>

#include <stdlib.h>

#include"Contacts.h"

int main()

{

struct ContactNode* start;

struct ContactNode* t;

int i;

char Name[50],phoneNo[50];

for(i=1;i<=3;i++)

{

printf(" Person%d ",i);

printf("Enter name: ");

gets(Name);

printf("Enter phone number: ");

gets(phoneNo);

if(i==1)

{

start=CreateContactNode(t,Name,phoneNo);

t=start;

}

else

t=InsertContactAfter(t,Name,phoneNo);

printf("You entered: %s, %s ",t->ContactName,t->ContactPhone);

}

  

  

printf(" CONTACT LIST");

t=start; while(t)

{

PrintContactNode(t);

t=GetNextContact(t);

}

}

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

Explanation / Answer

//now your code is fine

//you need to include Contact.c in main.c

main.c

--------------------------------------------

#include <stdio.h>

#include <stdlib.h>
//modified..
//#include"Contacts.h"
#include"Contacts.c"

int main()

{

struct ContactNode* start;

struct ContactNode* t;

int i;

char Name[50],phoneNo[50];

for(i=1;i<=3;i++)

{

printf(" Person%d ",i);

printf("Enter name: ");

gets(Name);

printf("Enter phone number: ");

gets(phoneNo);

if(i==1)

{

start=CreateContactNode(t,Name,phoneNo);

t=start;

}

else

t=InsertContactAfter(t,Name,phoneNo);

printf("You entered: %s, %s ",t->ContactName,t->ContactPhone);

}

printf(" CONTACT LIST");

t=start; while(t)

{

PrintContactNode(t);

t=GetNextContact(t);

}

}

Contact.c

--------------------------------------

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include"Contacts.h"

struct ContactNode* CreateContactNode(struct ContactNode* p, char name[], char phone[]){

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[]){

struct ContactNode* temp;

if(p==NULL){

p=CreateContactNode(temp,name,phone);

return(p);

}

else{

temp=CreateContactNode(temp,name,phone);

p->nextNodePtr=temp;

}

return(temp);

}

struct ContactNode* GetNextContact(struct ContactNode* p) {

return p->nextNodePtr;

}

void PrintContactNode(struct ContactNode* p) {

printf(" Name: %s ",p->ContactName);

printf("Phone number: %s ",p->ContactPhone);

}

Contact.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[]);

struct ContactNode* InsertContactAfter(struct ContactNode* p,char name[], char phone[]);

struct ContactNode* GetNextContact(struct ContactNode* p);

void PrintContactNode(struct ContactNode* p);

#endif

output:-


Person1
Enter name:
surya
Enter phone number:
9876554
You entered: surya, 9876554

Person2
Enter name:
phani
Enter phone number:
19384784
You entered: phani, 19384784

Person3
Enter name:
rrk
Enter phone number:
193274
You entered: rrk, 193274

CONTACT LIST
Name: surya
Phone number: 9876554

Name: phani
Phone number: 19384784

Name: rrk
Phone number: 193274


Process exited normally.
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote