1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
crimeas [40]
3 years ago
6

You are !o code and execute a C program to input narnes ard addresses t]rat are in alphabctic order and output the names and add

resses to a new file in zip code order. Maxirnum of 50 names. lfre program should be modularize d and rvell documented. You must use a stnrcnrre for the names and acldress information. Allocate storage dlnamicrlly for each sruc0.rre. Use I/O redirection for the input and ouputfilcs. This program mustbe done with ar array of pointers to structures. Do notuse art uray o[ stmcnrres. This progarn MUST use multiple filc format You may use slring handling functions for tiris lab.
Computers and Technology
1 answer:
alexgriva [62]3 years ago
4 0

Answer:

#define MAX 50

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

struct address

{

char name[MAX];

char street[MAX];

char city[MAX];

char zip[10];

};

void in(struct address *, int *);

void sort(struct address *, int);

void out(struct address *, int);

int main(){

struct address *ADDRESS = (struct address *)malloc(50*sizeof(struct address));

int n=0;

in(ADDRESS, &n);

sort(ADDRESS, n);

out(ADDRESS, n);

}

void in(struct address *ADDRESS, int *num)

{

FILE *fp;

char fname[MAX];

printf("Enter input file name: ");

scanf("%s", fname);

fp = fopen(fname, "r");

if (fp == NULL)

{

printf("Unable to open file");

exit(1);

}

int a = 0;

while (!feof(fp))

{

//ADDRESS = (struct address *)realloc(ADDRESS, (a + 1) * sizeof(struct address));

if(a>=50)

break;

fscanf(fp, "\n%[^\n]s", (ADDRESS+a)->name);

fscanf(fp, "\n%[^\n]s", (ADDRESS+a)->street);

fscanf(fp, "\n%[^\n]s", (ADDRESS+a)->city);

fscanf(fp, "\n%[^\n]s", (ADDRESS+a)->zip);

a++;

}

printf("Successfully %d read from file\n", a);

*num = a;

}

void sort(struct address *ADDRESS, int num){

int i, j;

for(i=0; i<num; i++){

for(j=i+1; j<num;j++){

if(strcmp((ADDRESS+i)->zip, (ADDRESS+j)->zip)>0){

struct address t = *(ADDRESS+i);

*(ADDRESS+i) = *(ADDRESS+j);

*(ADDRESS+j) = t;

}

}

}

}

void out(struct address *ADDRESS, int num)

{

FILE *fp;

char fname[MAX];

printf("Enter output file name: ");

scanf("%s", fname);

fp = fopen(fname, "w");

if (fp == NULL)

{

printf("Unable to open file");

exit(1);

}

int a;

for(a=0; a<num; a++)

{

fprintf(fp, "%s\n", (ADDRESS+a)->name);

fprintf(fp, "%s\n", (ADDRESS+a)->street);

fprintf(fp, "%s\n", (ADDRESS+a)->city);

fprintf(fp, "%s\n", (ADDRESS+a)->zip);  

}

printf("Successfully %d Write to file\n", a);

fclose(fp);

}

Explanation:

You might be interested in
What is the small window that pops up in a application that requieres a response for the user
Marina CMI [18]

Answer:

that is called a popup box. or a alert box

assuming you are talking about this

3 0
3 years ago
Read 2 more answers
A(n) ______ is an output device that visually conveys text, graphics, and video information.
polet [3.4K]
The answer is Printer. hope this helped :)

3 0
4 years ago
NEED HELP NOW 66 POINTS WILL MARK BRAINLIEST!! For the independent reading all you have to do is pick a grade six book that you
nlexa [21]
1a
2a
3b
4d
5c
6d
7b
8c
9a
10c
6 0
3 years ago
Does anyone have 2.19.4 Guess a number 2.0 code for codehs?
lubasha [3.4K]

Answer:

I'm trying to create a program that will ask the user for an exam score in the range 0 to 100. ... I want to take the python course but I have not class code, anyone can help?

Explanation:

3 0
3 years ago
National Public Radio is controlled by a combination of government, corporate sponsorship, and individual donations.
Shkiper50 [21]

so what's the question?

4 0
3 years ago
Read 2 more answers
Other questions:
  • ___ consists of a central conductor surrounded by a shield (usually a wire braid).
    9·1 answer
  • What do green squiggly lines under text indicate?
    14·1 answer
  • Write an algorithm that receives a number from the user (you can store the number in a variable called N). Then the algorithm sh
    8·1 answer
  • A new object of type list is created for each recursive invocation of f.A. TrueB. False
    15·1 answer
  • Write a structured algorithm that prompts the user to input the name and price of an item and the quantity purchased. It should
    10·1 answer
  • I am a mouse, but im not a mouse.<br><br> What am I?
    12·1 answer
  • Define the html code to insert a heading
    14·1 answer
  • The Klez virus was a worm created to "spoof others. What is "spoofing"?
    6·1 answer
  • SummaryIn this lab, you complete a partially prewritten Java program that uses an array.The program prompts the user to interact
    12·1 answer
  • ____ is an example of a set of prewritten classes that allows you to access data stored in a database.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!