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
Alex leads a team of eight members. Arrange his tasks in sequential order of phases of group dynamics. What are the stages in gr
Alborosie

Answer and Explanation

There are five stages of group development which Alex should follow.

i) Stage 1: Forming-this is where he forms a team which will follow the other stages.

ii)Stage 2: Storming - In this stage is where the members set their goals and boundaries.

iii)Stage 3: Norming- This is where the team comes together in terms of ideas. In this stage members are ready to move forward with big expectations.

iv)Stage 4: Performing.-This is where  now the team is now accomplishing or implements their ideas and they are now getting the benefits.In this stage members argue positively.

v)Stage 5: Adjourning-This is the stage where the group has accomplished their mission.And now the group is dissolved

7 0
3 years ago
What is the name of the computer that access shared resources on the network<br><br>​
tangare [24]

Answer:

what is the name of the computer that access shared resources on the network

5 0
3 years ago
Read 2 more answers
A Python data model defining the state of a game for Tic-Tac-Toe. You must fully describe the notion of a state of the game, lim
Artist 52 [7]

Answer:

Check the explanation

Explanation:

Here in this game of Tic-Tac-Toe, it is using the TPGE engine which is a Tiny Python Game Engine. Let's talk about its functions like:-

def image_type(img): In this function, it is simply taking image as a parameter and returning its object type like DISC if the image is in graphical form, TEXT if it is a string, and LINE if it is other than the mentioned object.

def convert_image(img):  In this function, it is simply taking image as a parameter and returning an equivalent graphical object as understood by John Zelle's. Mainly comparing for three things in this function and those are: if image equals to DISC then it is calling convert_circle(function), if image equals to LINE then it is calling convert_line(function), and if image equals to TEXT then it is calling convert_text(function),

def convert_circle(x): This function takes a list( a group of values) and makes a circle at the center of the window and the circle's radius is coming from the list.

convert_text, convert_line, convert_circle are only creating text, line, and circle and then returning it.

def graphical_elements(images): This function is taking image as a parameter and then extracting shape and color from the image and then calling convert_image(shape) and convert_type(shape) and it gives us graphic and kind respectively. Now it is checking whether kind equals to DISC If yes then filling color on the window else, setting the outline of the window

def run(): Here it is finally running the game with required parameters, the whole game is continously running under the while loop.

That's all

8 0
4 years ago
Which internetworking device makes computers that are connected to separate segments appear and behave as if they're on the same
Temka [501]

NIC Ports use which RJ connector? RJ-45 internetworking device makes computers that are connected to separate segments appear and behave as if they're on the same segment.

There's a lot of confusion out there about which NIC ports use which RJ connectors. RJ-45 internetworking devices make computers that are connected to separate segments appear and behave as if they're on the same segment. So, which one do you use?

The answer is actually quite simple. If you're connecting two computers together, you'll need to use an RJ-45 cable. If you're connecting a computer to a modem or router, you'll need to use an RJ-11 cable.

RJ-45 cables are actually quite common and can be found at most electronics stores. If you're not sure which one you need, just ask a sales associate for help.

Learn more on internetworking device here:

brainly.com/question/28342757

#SPJ4

3 0
2 years ago
How many bytes is a yobibyte
Tanzania [10]
i think the answer is 1 x 10^24 bytes
6 0
3 years ago
Read 2 more answers
Other questions:
  • The length of time the valve is open, expressed in degrees of crankshaft rotation, is called camshaft
    10·1 answer
  • Certain medications can increase risk of obtaining a sunburn true or false
    12·1 answer
  • Identify characteristics of top-down programming design. Choose all that apply.
    13·1 answer
  • The type of human hair wig that is the most costly is:
    12·1 answer
  • Write a program that use a switch statement whose controlling expression is the variable area code. If the value of area_code is
    12·1 answer
  • Please check my answer! (Java)
    6·1 answer
  • Which two programming languages require the program to be converted into executable code using a compiler? (Choose two.)
    5·1 answer
  • How to prepare and draw a corresponding flowchart to compute the sum and product of all prime numbers between 1 and 50
    7·1 answer
  • Question #8
    5·1 answer
  • Selection Sort List the resulting array after each iteration of the outer loop of the selection sort algorithm. Indicate the num
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!