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: 3766354 • 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.

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

Below are the code of 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.

// define record.h

#ifndef RECORD_H

#define RECORD_H

#define size 40

#define MAX_CITY 50 // two source files define the values CITIZENS/MAXCITYREC as 50

typedef struct{

    char name[size];

    char streetadd[size];

    char citystate[size];

    char zcode[size];

}CITYREC;

int readin(CITYREC *city[]);

void writot(CITYREC *city[], int n);

#endif RECORD_H

    for(int i = 0;i<n;i++){

        printf("%s %s %", city[i]->name, city[i]-> streetadd, city[i]->citystate, city[i]->zcode);

    }

}

#define CITIZ 50