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

Code and execute a C program to input names and addresses that are in alphabetic

ID: 3823957 • Letter: C

Question

Code and execute a C program to input names and addresses that are in alphabetic order and output the names and addresses to a new file in zip code order. Maximum of 50 names.

The program should be modularized and well documented. you must use a structure for the names and address information. allocate storage dynamically for each structure. use I/O redirection for the input and output files. This program must be done with an array of pointers to structures. ""do not use an arrray of structures"". this program MUST use multiple file format (.c and 2 .h files) You may use string handling functions for this lab.

Sort in ascending order.

input: create a data file of names and addresses in alphabetic order(by name) as follows:

first line: last name, first name

second line: street address

third line: city and state

fourth line: zip assume

no errors, which means that you have to type carefully)

output:

The program is to create a new file of names and addresses in zip code order with the above format. If duplicate records (2 or more) occur in the input file, only include one copy in the input file. YOU MUST USE POINTERS TO STRUCTURES AND MALLOC. NO GLOBAL VARIABLES.

Explanation / Answer

record.h :-

#define size 40

#include <stdio.h>

#include <stdlib.h>
#include <string.h>

typedef struct{
char Input_Name[size];
char Input_Address[size];
char Input_CITY_state[size];
char Input_ZipCode[size];
}in_City_rec;

typedef in_City_rec *cityobj;
cityobj p;

int readin(in_City_rec *in_City[]);
void writot(in_City_rec *in_City[], int Number);

record.c

#define MAXCITYREC 50
#include "record.h"

char buff[81];

int readin(in_City_rec *in_City[]){
int Number=0;

while((gets(buff)!=NULL)&&(Number<MAXCITYREC)){
p=(cityobj)malloc(sizeof(in_City_rec));
strcpy(p->Input_Name,buff);
gets(p->Input_Address);
gets(p->Input_CITY_state);
gets(p->Input_ZipCode);
in_City[Number++]=p;
}
return Number;
}

void writot(in_City_rec *in_City[], int Number){
in_City_rec *pcr;
for(pcr=*in_City;pcr<*in_City+Number;pcr++){
printf("%s %s %s %s ", pcr->Input_Name, pcr->Input_Address, pcr->Input_CITY_state, pcr->Input_ZipCode);
}
}

Main.c

#define CITIZENS 50
#include "record.h"

int main(void){
in_City_rec *in_City[CITIZENS];

int n=readin(in_City);
writot(in_City, n);
return 0;
}

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