Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that reads 10 integers from a file, stores the integers in an array, sorts, and prints the values in the array. You

Write a program that reads 10 integers from a file, stores the integers in an array, sorts, and prints the values in the array.

You should have the following functions:

1. A function that reads the integer values from a file and stores the integers in an array

2. A function that sorts an array of 10 integers

3. A function that prints an array of 10 integers.

Below are a few of the steps you will need:

1. Create a variable of type FILE that is a pointer (FILE *).

2. Open the file for reading, the file name will be supplied on the command line.

3. Validate the file opened appropriately.

4. Create an integer array of size 10 initializing all values to 0.

5. Call the necessary functions to read, sort, and print the data.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

#include

#include

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

{

FILE *ifp, *ofp;

int num;

if(argc < 3)

{

printf("Usage Error: ");

exit(1);

}

ifp = fopen(argv[1], "r");

if (ifp == NULL)

{

printf("Can't open input file %s! ", argv[1]);

exit(1);

}

ofp = fopen(argv[2], "w");

if (ofp == NULL)

{

printf( "Can't open output file %s! ", argv[2]);

exit(1);

}

fscanf(ifp, "%i", &num);

fprintf(ofp, "%i", num);

fclose(ifp);

fclose(ofp);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

=+ Are they breakable for any reason?

Answered: 1 week ago

Question

=+When and under what circumstances are contracts renegotiated?

Answered: 1 week ago