julio7264
15.12.2020 •
Computers and Technology
The picture above is a description of the C code below. Please modify the C below so that it uses FILE HANDLING (fopen, fputs, fgets, 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);
Solved
Show answers
More tips
- H Health and Medicine How to Get Rid of Dandruff?...
- S Sport How to Choose Tennis Rackets?...
- H Health and Medicine AKDS Vaccination: Ensure Your Child s Safety...
- H Health and Medicine Naskol ko Opasen Ukus Kleshcha i Kak Ego Raspoznat...
- C Computers and Internet How to Delete Your Account on Odnoklassniki...
- H Health and Medicine What to Do When Your Jaw Locks Up?...
- G Goods and services What Are the Most Popular Services?...
- P Philosophy How did the concept of module arise in computer science?...
Answers on questions: Computers and Technology
- C Computers and Technology Using the fafsa form , you can for apply for what...
- C Computers and Technology An effective technology for e-training and e-learning is which uses computer graphic displays that the user can adjust during the decision-making process to see the results...
- E English How can the exercise instructor see that winston is not touching his toes?...
- B Business What is a certificate of incorporation? a. taxes a stockholder pays b. a license to form a corporation c. a report filed with the cfo d. stocks equal to a majority interest...
- M Mathematics Does anyone know what this answer is...
- H History Which record-keeping strategy was used by the egyptian and the mesopotamian civilizations? using papyrus reeds as permanent record employing trained scribes to write documents...
- H History Where was new york before becoming a state?...
- P Physics What state of matter would spread apart and fill all the space available to them...
- B Biology Which series correctly lists the order of species (from a to e. that belong on the timeline?...
- E English In the space below write a paragraph on a topic of your choice use at least fiffteen different pronouns to make your pronouns stand out, write each pronoun entirely in capitals...
Ответ:
ECC (Error-correcting code) memory
Explanation: Error correcting code memory is the memory that has the capability of detection and correcting the error arising in the data.The internal data is the most effected data from the corruption and damage.It is the memory used in the computer and other operating system because it has less tolerance towards data corruption.
The technician should use the ECC memory for the building of the client station.This will protect the system and the data from getting in any circumstance.