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

C Program --------------------------------------- Description: Input consists of

ID: 3697517 • Letter: C

Question

C Program

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

Description: Input consists of names and addresses in the below format: There should be NO USER PROMPTS, all input will come from a file using I/O redirection. No File handling required in program. Output should be same line by line as input and sorted by zip code.

FirstName LastName

2222 Address Lane

My City, State

90210

Chegg Senior

5895 This Street

Programming, NY

92310-4532

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

The program is supposed to take this, store it in a struct, then after all input is received it should output all addresses in zip code order from lowest to heighest. All memory must be DYNAMICALLY ALLOCATED as data is input. there is no Minimum or Maximum to how many addresses that can be entered. Addresses should be output in the same style as they are input with a space between each address.

Note that a zip code entered in this format (90210-1234) should also be accepted.

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

Rules/Notes:

-Must use Dynamic Memory Allocation

-Must use Pure Pointer Notation

-Do NOT Delete duplicate addresses

-No Global Variables

-Sort from lowest Zip to Highest

Explanation / Answer

#include<stdio.h>

#include<conio.h>

#include<string.h>

struct person

{

char name[10];

int zcode;

Char stname[20];

};

typedef struct person NAME;

NAME stud[10],temp[10];

void main()

{

int no,i;

void sort(int N);

clrscr();

fflush(stdin);

printf("Enter the number of students in the lists ");

scanf("%d",&no);

for(i=0;i<no;i++)

{

printf(" Enter the name of person %d : ",i+1);

fflush(stdin);

gets(std[i].name);

printf("Enter the zip code of %d : ",i+1);

scanf("%d",&stud[i].zcode);

temp[i]=stud[i];

}

printf(" ****************** ");

printf("Names before sorting ");

for(i=0;i<no;i++)

{

printf("%-10s %3d ",temp[i].name,temp[i].zcode);

}

sort(no);

printf(" ****************** ");

printf(" Names after sorting ");

printf(" ******************* ");

for(i=0;i<no;i++)

{

printf("%-10s %3d ",stud[i].name,stud[i].zcode);

}

printf(" *************** ");

}

void sort(int N)

{

int i,j;

NAME temp;

for(i=0;i<N-1;i++)

{

for(j=i+1;j<N;j++)

{

if(strcmp(stud[i].name,stud[j].name)>0)

{

temp=stud[i];

stud[i]=stud[j];

stud[j]=temp;

}

}

}

}