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
mash [69]
3 years ago
10

In this lab you will write a C program to sort an array of strings. The program will: Create an array of 50 strings; each string

can hold up to 30 characters. Write a function to read strings from the file "strings.dat" into your array. Read until EOF and keep track of how many strings you read, as it may be less than 50. Then pass this variable to your print and sort functions so they know how many strings to print and sort. Use fopen to open the file and fgets to read each string. Write a function to sort the strings. Only sort the array entries that contain strings read from the file. See below for pseudocode for selection sort. Write a function to swap two strings, which will be called by your sort function. Pass the array and the subscripts of the two strings that need to be swapped. Write a function to print out the array entries that were read into the array. Use printf. Your main function should call the functions to read into the array, print the array, sort the array, and print the array again.
Computers and Technology
1 answer:
andrezito [222]3 years ago
6 0

Answer:

See explaination

Explanation:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void swap(char *arr[], int i, int minIdx)

{

char temp[30];

strcpy(temp, arr[i]);

strcpy(arr[i], arr[minIdx]);

strcpy(arr[minIdx], temp);

}

void sort(char *arr[], int n)

{

for (int i = 0; i < n - 1; i++)

{

int minIdx = i;

int minV = 10000;

char min[30];

strcpy(min, arr[i]);

for (int j = i + 1; j < n; j++)

{

int a = strcmp(min, arr[j]);

if (a < 0)

{

strcpy(min, arr[i]);

minIdx = j;

}

}

swap(arr, i, minIdx);

}

}

void print(char *arr[], int n)

{

for (int i = 0; i < n; i++)

printf("%s", arr[i]);

}

void read(char *arr[], int *n)

{

FILE *file = fopen("strings.dat", "r");

char line[30];

*n = 0;

printf("Reading from file...\n");

while (fgets(line, 30, file))

{

strcpy(arr[(*n)++], line);

}

print(arr, *n);

}

int main(int argc, char const *argv[])

{

char *arr[50];

for (int i = 0; i < 50; i++)

arr[i] = (char *)malloc(sizeof(char) * 30);

int len;

int n = 0;

read(arr, &n);

printf("\n-------------------------\nAfter sorting\n");

sort(arr, n);

print(arr, n);

}

You might be interested in
!!! 20 points !!!!!
puteri [66]

Answer: I need more info to answer this question

Explanation:

8 0
2 years ago
Using media allows us to:
neonofarm [45]

Answer: "Contribute and Create"

Explanation: While, yes, technology and digital media does tend to isolate us from the real world, it is a great tool for contributing to society!

5 0
3 years ago
A network using multiple cell towers falls under which type of network?
erastova [34]

Answer:

man

Explanation:

multiple area network

8 0
4 years ago
___ is the most important variable that is measured and controlled in a commercial hvac system.
Pavel [41]

The parameter being monitored and controlled is the controlled variable. The dry-bulb temperature of the air leaving the cooling coil is the controllable variable in this particular instance. The sensor assesses the state of the controlled variable and provides the controller with an input signal.

<h3>What is a HVAC ?</h3>

The employment of various technologies for heating, ventilation, and air conditioning is done to regulate the temperature, humidity, and cleanliness of the air in a closed environment. Its objective is to provide adequate indoor air quality and thermal comfort.

  • To cool or heat a building, the main unit of a ducted system forces air via a network of air ducts. On the other hand, ductless systems don't have air ducts and employ different techniques to spread cleaned air across a room.

Learn more about HVAC system here:

brainly.com/question/20264838

#SPJ4

6 0
2 years ago
Access time is:________.
worty [1.4K]

Answer:

B) the time it takes for the required sector to position itself under the read/write head.

Explanation:

In Computer science, Access time is the time it takes for the required sector to position itself under the read/write head. It is usually measured in milliseconds.

It is the speed of the storage device.

5 0
4 years ago
Other questions:
  • Theâ ______ is a large worldwide collection of networks that use a common protocol to communicate with one another.
    5·1 answer
  • Which data table display compares report metrics to the website average?
    6·1 answer
  • A ________ allows a hacker to gain access to your computer and take almost complete control of it without your knowledge. zombie
    15·1 answer
  • data structureWe have two containers: one has a capacity of three gallons of water, the other five gallons. Both are initially e
    11·1 answer
  • A newspaper publishes a negative editorial on how local politicians are dragging their feet in building a new bridge. Select the
    10·2 answers
  • Big data are used to _____. Select 3 options.
    5·1 answer
  • What is an outcome in a game? Don't search google just give me an answer
    9·1 answer
  • What are the steps in preparing a bootable USB installer?​
    11·1 answer
  • Can you help me with Computer issues graphic organizer?<br> Will give out brainly
    6·1 answer
  • Can someone please help me with this .
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!