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

Segregate the homes by zip code. Write a program to create a text file for each

ID: 3543142 • Letter: S

Question

Segregate the homes by zip code. Write a program to create a text file for each zip code in the file. For example, if the zip codes 12345, 95678, and 34872 are in the file, you should end up with three files: 12345.txt, 95678.txt, and 34872.txt.

The input file is read from standard input, as shown in the textbook.

To each file just write the address of the home.


The name of this program should be zips.c

The file name is homelistings.csv.

These are a few lines that are in file:

95821,70127335,4121 Edison Ave,295000,3,2,1741

95621,80023034,7613 Sara Lynn Way,187900,3,2,1431

95832,80021633,1986 Danvers Way,209000,4,2,180

it starts off with zip code, id, address, price, # of bedrooms, # of bathrooms, sqaure footage.

There about 40 zip codes in file.

Explanation / Answer

#include #include int main() { char a[10000],fname[1000],addr[10000]; int len,i,cnt=0,fcnt=0,adcnt=0; FILE *fd = fopen("homelistings.csv","r"); if(fd==NULL) { printf("ERROR "); } else { fread(a,10000,1,fd); len = strlen(a); for(i=0;i