I understand that you do not have all the information needed to give a complete
ID: 3731370 • Letter: I
Question
I understand that you do not have all the information needed to give a complete solution.But heres the gist: I have a file that produces a sorted array of numbers, but i want to print that array into an output file. Not sure if i should make a completely different file? or revise the original? (I am using C)
1. (10 points) For this problem your mission is to further revise the sort program from Homework 5 so that rather than generating random data it reads the values to sort from a file and writes the sorted values to another file. The completed program should take two command-line arguments giving the names of the input and output files. (It should not prompt the user for anything.) The program should nt appropriate error messages if not enough arguments are supplied, if it cannot open the input and output files, or if the input file contains anything but a sequence of integers. Since we have not yet talked about how to make arrays larger at runtime, just write the program with a fixed-size array for holding input, and have the program print an error message if the number of input values exceeds the size of the array. It's up to you whether you keep the part of the existing program that checks whether the sort succeeds (I say" might as well"); if you do, just have it print to standard output as before.Explanation / Answer
Solution :-
as per given in Question sorted array should be in another file (completly different file . if You want to print that array into another output file I will show you code below.
/*
* C program to create a file called output.txt and store output into it
*/
#include <stdio.h>
void main()
{
FILE *fptr;
char name[20];
/* open for writing */
fptr = fopen("output.txt", "w");
if (fptr == NULL)
{
printf("File does not exists ");
return;
}
// write your output here
fprintf(fptr, output_array[]);
fclose(fptr);
}