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
Kruka [31]
3 years ago
5

The picture above is a description of the C code below. Please modify the C below so that it uses FILE HANDLING (fopen, fputs, f

gets, etc.).
You may also be required to use command line parameters for the input file, thank you.

main.c:

#include "contacts.h"
#include
#include

int main(void) {
size_t size;
contact **c = alloc_contacts(MAX_CONTACTS);
size = get_contacts(c);
if (size == 0)
perror("get_contacts failed");
sort_contacts(c, size);
print_contacts(c, size);
free_alloc(c, size);

return 1;
}

contacts.c:


#include "contacts.h"
#include
#include

/* Allocate space for n number of contacts.
Then return a pointer to the array */
contact **alloc_contacts(size_t n) {
contact **c = malloc(n * sizeof(contact *));
if (c == NULL)
perror("Malloc failed");

return c;
}

/* Populate contact array with values from stdin */
size_t get_contacts(contact **c) {
char zip[64];
size_t size = 0;
for (size_t i = 0; i < MAX_CONTACTS; i++, size++) {
/* allocate contact struct as needed */
c[i] = malloc(sizeof(contact));
if (c[i] == NULL)
perror("Malloc failed");
fgets(c[i]->name, MAX_BUF, stdin);
fgets(c[i]->address, MAX_BUF, stdin);
fgets(c[i]->locale, MAX_BUF, stdin);
fgets(zip, sizeof(zip), stdin);
c[i]->zip = atoi(zip);
/* if EOF reached, break loop to avoid more allocs */
if (feof(stdin))
break;
}

return c ? size : 0;
}

void swap(contact *a, contact *b) {
contact temp = *b;
*b = *a;
*a = temp;
}

/* Bubble sort O(n^2) */
void sort_contacts(contact **c, size_t n) {
int i, j = n, s = 1;
while (s) {
s = 0;
for (i = 1; i < j; i++) {
if (c[i]->zip < c[i - 1]->zip) {
swap(c[i], c[i - 1]);
s = 1;
}
}
j--;
}
}

/* Loop over contact array printing each contact element */
void print_contacts(contact **c, size_t size) {
for (size_t i = 0; i < size; i++)
printf("%s%s%s%d\n", c[i]->name, c[i]->address, c[i]->locale, c[i]->zip);
}

void free_alloc(contact **c, size_t size) {
for (size_t i = 0; i < size; i++) {
free(c[i]);
}
free(c);
}

contacts.h:

#pragma once
#define MAX_CONTACTS 50
#define MAX_BUF 50

typedef struct {
char name[MAX_BUF];
char address[MAX_BUF];
char locale[MAX_BUF];
unsigned int zip;
} contact;

contact **alloc_contacts(size_t n);
size_t get_contacts(contact **c);
void print_contacts(contact **c, size_t size);
void sort_contacts(contact **c, size_t n);
void swap(contact *a, contact *b);
void free_alloc(contact **c, size_t size);

Computers and Technology
1 answer:
siniylev [52]3 years ago
3 0

Answer: i just learned something new.

Explanation:

You might be interested in
Think of a genre (science, music, math, sports, video games, etc.) and create at least 10 questions. You can decide whether you
mojhsa [17]

<em>Answer:</em>

<em>When listing to studying music or calm music it will help you considerate on a test or any home work that you are doing </em>

<em>Explanation:</em>

<em>Since 2006, two UCF professors neuroscientist Kiminobu Sugaya and world-renowned violinist Ayako Yonetani have been teaching one of the most popular courses in The Burnett Honors College. “Music and the Brain” explores how music impacts brain function and human behavior, including by reducing stress, pain and symptoms of depression as well as improving cognitive and motor skills, spatial-temporal learning and neurogenesis, which is the brain’s ability to produce neurons. Sugaya and Yonetani teach how people with neurodegenerative diseases such as Alzheimer’s and Parkinson’s also respond positively to music. </em>

<em> </em>

<em>“Usually in the late stages, Alzheimer’s patients are unresponsive,” Sugaya says. “But once you put in the headphones that play [their favorite] music, their eyes light up. They start moving and sometimes singing. The effect lasts maybe 10 minutes or so even after you turn off the music.” </em>

<em> </em>

<em>This can be seen on an MRI, where “lots of different parts of the brain light up,” he says. We sat down with the professors, who are also husband and wife, and asked them to explain which parts of the brain are activated by music.</em>

7 0
3 years ago
Complete the printtictactoe function with char parameters horizchar and vertchar that prints a tic-tac-toe board with the charac
lora16 [44]
Void printtictactoe(char horizchar, char vertchar)
{
int i,j;
int scale = 5;

for(j=0; j<3; j++) {
   for (i = 0; i < scale; i++)
      printf("%*c%*c\n", scale+1, vertchar, scale+1, vertchar);
      if (j < 2) 
         for (i = 0; i < (scale * 3)+2; i++)
             printf("%c", horizchar);
             printf("\n");
    }
}

I left out many braces because of the layout issues with this website. There is a scale factor you can set to the desired size of the board cells!
3 0
3 years ago
In data flow diagrams, an individual who originates data is:
NemiM [27]
B. A data source is the answer. Hope it’s right.
3 0
4 years ago
why is it when i go to social it shows a post from February it's like i am not with the ppl posting rn
Fittoniya [83]
Not sure. if youre online try messing with the filters if there are some, if youre on the app try updating it.
3 0
3 years ago
If a destructive program is running that might be destroying evidence what should be done
Vikentia [17]
The choices can be found elsewhere and as follows:
a. perform an immediate full backup
b. attempt to end the process
c. pull the power cable
d. record the destruction using a video capture of the screen

I think the correct answer is option a. If a destructive program is running that might be destroying evidence, then perform an immediate full backup. 
3 0
3 years ago
Other questions:
  • You have a large company, and it is important to your business that your employees' work is backed up regularly. Which network w
    5·1 answer
  • You were replying to e-mail when suddenly your computer started to display random messages, and stopped responding to keyboard a
    10·1 answer
  • A virus that propagates using the internet or another computer network is called __________.
    10·1 answer
  • 50 POINTS PLEASE HELP MEEEEEEEEE!!!!!!
    6·2 answers
  • Learning in a digital environment is also called learning.
    6·2 answers
  • Which of the following is true regarding a class and interface types? Group of answer choices You can convert from a class type
    9·1 answer
  • What did Adam and Eve look like?
    7·2 answers
  • Evaluating algebraic expressions 8(x+2)when x =6
    7·1 answer
  • PLEASE HELP!!!
    11·2 answers
  • The blue section of the following Venn diagram could represent which of the following Boolean statements?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!