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

Create a Code Blocks project named LinkedLists. This program will use a set of d

ID: 3916916 • Letter: C

Question

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. Please use the C language and include source code comments.

Explanation / Answer

LinkedLists.c

#include<stdio.h>
#include<conio.h>

struct Contactinfo
{
char name[40];
unsigned long long mobile;
unsigned long pincode;
struct Contactinfo *next;
};

struct Contactinfo *start=NULL;

struct Contactinfo *getcontactinfo(void);
void addContactInfoToList(struct Contactinfo *info);
void display();
void main()
{
int i;
clrscr();
for(i=1;i<=2;i++)
{
addContactInfoToList(getcontactinfo());
}
display();
getch();
}

struct Contactinfo *getcontactinfo(void)
{
struct Contactinfo *newnode;
newnode=(struct Contactinfo*)malloc(sizeof(struct Contactinfo)) ;
printf(" Enter the name,mobile no,pincode");
scanf("%s%llu%lu",newnode->name,&newnode->mobile,&newnode->pincode);
newnode->next=NULL;
return newnode;
}

void addContactInfoToList(struct Contactinfo *info)
{
if(start==NULL)
{
start=info;
}
else
{
struct Contactinfo *temp;
temp=start;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=info;
}
}

void display()
{
struct Contactinfo *temp;
temp=start;
printf(" contact details are: ");
while(temp!=NULL)
{
printf(" name:%s ",temp->name);
printf("mobile no:%llu ",temp->mobile);
printf("pincode:%lu ",temp->pincode);
temp=temp->next;
}
printf(" END");

}