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

Please use C language Create a Code Blocks project named LinkedLists. This progr

ID: 3918432 • Letter: P

Question

Please use C language

Create a Code Blocks project named LinkedLists. This program will use a set of data structures into which the user will enter contact information.

Globally declare a ContactInfo struct.

Create a function that asks for contact information and places the information into a struct.
ContactInfo *getContactInfo( void );

Call getContactInfo ten times from a for loop, and each time add the new data structure to the end of the list (use a function named addContactInfoToList( ContactInfo *info ) to add the new data structure to the list)..

Write a function that displays all of the data in the list.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define MAX 30

struct ContactInfo
{
int contactno;
char name[MAX];
struct ContactInfo *next;
};

/*********************************************************************/
/* Function to insert a node at the front of the linked list. */
/* front: front pointer, id: ContactInfoloyee ID, name: ContactInfoloyee name */
/* Returns the new front pointer. */
/*********************************************************************/

struct ContactInfo* addContactInfoToList(struct ContactInfo *front, int id, char name[], char desg[])
{
struct ContactInfo *newnode;

newnode = (struct ContactInfo*) malloc(sizeof(struct ContactInfo));

if (newnode == NULL)
{
printf(" Allocation failed ");
exit(2);
}
newnode->contactnumber = id;
strcpy(newnode->name, name);
newnode->next = front;
front = newnode;
return(front);
} /*End of addContactInfoToList() */


/* Function to display a node in a linked list */
void printNode(struct ContactInfo *p)
{
printf(" ContactInfoloyee Details... ");
printf(" ContactInfo No : %d", p->contactnumber);
printf(" Name : %s", p->name);
printf("------------------------------------- ");
} /*End of printNode() */

void display(struct ContactInfo *front)
{
struct ContactInfo *ptr;
for (ptr = front; ptr != NULL; ptr = ptr->next)
{
printNode(ptr);
}
} /*End of display() */

//to get information from user
void getContactInfo(struct ContactInfo *linkList)
{
printf(" Enter the Contact Number : ");
scanf("%d", &contactno);

printf("Enter the name : ");
fflush(stdin);
gets(name);

linkList = addContactInfoToList(linkList, contactno, name, desig);
}

/* The main() program begins */
void main()
{
struct ContactInfo *linkList;
char name[21];

int contactno;
int i;

linkList = NULL;

printf(" Welcome to demonstration of singly linked list ");

for(i=0;i<10;i++)
{
getContactInfo(linkList);

}
//to display all the nodes .i.e contact info of employees with name
if (linkList == NULL)
{
printf(" List ContactInfo.");
}
display(linkList);

} /*End fo main()*/