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
Given four inputs: a, b, c &amp; d, where (a, b) represents a 2-bit unsigned binary number X; and (c, d) represents a 2-bit unsi
Amiraneli [1.4K]

Answer:

z = a.c' + a.b.d' + b.c'.d'

Explanation:

The truth table for this question is provided in the attachment to this question.

N.B - a' = not a!

The rows with output of 1 come from the following relations: 01 > 00, 10 > 00, 10 > 01, 11 > 00, 11 > 01, 11 > 10

This means that the Boolean expression is a sum of all the rows with output of 1.

z = a'bc'd' + ab'c'd' + ab'c'd + abc'd' + abc'd + abcd'

On simplification,

z = bc'd' + ab'c' + ac'd' + ac'd + abc' + abd'

z = ac' + abd' + bc'd'

Hope this helps!

6 0
4 years ago
Select the correct answer.
zmey [24]

the answer should be the letter a

3 0
4 years ago
Read 2 more answers
The help desk received a call from a user who cannot get any print jobs to print on the locally shared printer. While questionin
erma4kov [3.2K]

Answer:

a. Power cycle the printer.

Explanation:

Power Cycle: To unplug the printer and restart it, is called power cycling. The peripheral devices often tend to stop working and the cause of this is not always easily figured out. So the first and easiest way that can be done to fix this issue is to run a power cycle. For this, you have to turn off the printer and unplug it. Then wait for a few seconds (at least 30) and plug in the printer again. Turn the printer on. Power cycle helps to resolve many basic issues. It is the easiest step to take before checking the printer cable, reinstalling printer or resetting the print spooler.

4 0
3 years ago
You can delete any content control by ____ it, and then clicking remove content control on the menu that opens.
Bezzdna [24]
<span>You can delete any content control by Right Clicking it, and then clicking remove content control on the menu that opens.</span>
8 0
4 years ago
Write a Python program called wdcount.py which uses a dictionary to count the number of occurrences of each word (ignoring case)
Art [367]

The program is an illustration of loops.

<h3>What are loops?</h3>

Loops are program statements used to perform repetition

<h3>The wordcount.py program</h3>

The program written in Python, where comments are used to explain each line is as follows

# This opens the file in read mode

text = open("myFile.txt", "r")

# This creates an empty dictionary

d = dict()

#This iterates through the text

for line in text:

# This splits the line into words, after removing leading & trailing spaces, and newline characters

words = line.strip().lower().split(" ")

# This iterates through all the words

for word in words:

 # The following if condition counts the occurrence of each word

 if word in d:

  d[word] = d[word] + 1

 else:

  d[word] = 1

#This prints the words and their frequencies, in descending order

for w in sorted(d, key=d.get, reverse=True):

   print(w, d[w])

Read more about loops at:

brainly.com/question/16397886

5 0
2 years ago
Other questions:
  • How do I connect my CSS file and HTML page together? it's just not wanting to work for me. 
    5·1 answer
  • Ead the following scenario and then answer the question.
    10·1 answer
  • Which is the correct expansion of the term Internet? 
    9·2 answers
  • Which of the following is not given to a client computer when it is first installed on a TCP/IP network so that it has the appro
    9·1 answer
  • Entering the search criteria "B?" would yield which of the following results?
    6·1 answer
  • Write the definition of a function named fscopy. This function can be safely passed two fstream objects, one opened for reading,
    11·1 answer
  • Kristi, an event planner, wants to store caterers’ names and contact information in an organized manner. Kristi will MOST LIKELY
    13·1 answer
  • What are source data entry devices​
    13·1 answer
  • Question 1 (1 point)
    9·2 answers
  • Which part of project management considers if employees will work at home or in the office?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!