Question: Write a program in C language that can open a file to read. Please add comments inbetween functions to show what you did, thumbs up

Write a program in C language that can open a file to read. Please add comments inbetween functions to show what you did, thumbs up for that.

- it needs to read lines of a file, ( example is that the file can have 3 lines with 4 numbers each )

- needs to make a struct and put it into an array. ( use typedef struct if neccessary) -- use scanf and printf.

calculate the average, median, lowest number, highest number, sum, mode.

- print that data into the screen ( command prompt)

- lastly, print and write the data onto another file.

/* I wrote a small start as to how the program should go, Not sure if typedef should be added in there or not for array.

please finish the code */

#include 

int main () {

FILE *fileinput *fileoutput

int numbers[SIZE]

int minvalue, maxvalue, sum, average, mode, median, count = 0; // not sure what else to add here or if this is correct

float average;

// this opens the file to read?

fileinput = fopen("sampleinput.txt", "r");

if (fileinput == NULL) {

printf(" File can't be read. ");

} else {

while (count < SIZE ) ???? // not sure if this is needed or not.

fscanf(fileinput, "%d", &numbers[count++]); // once again not sure.

fclose(fileinput); // closes the file?

sum = getsum(numbers);

average = (float) sum/ count

// not sure about rest. please continue this if there is anything wrong or missing.

...................

// opening the output file for writing.

fileoutput = fopen ("sampleoutput.txt "w")

if (fileoutput == NULL) {

printf(" File can't be opened to write results. ");

} else {

// writing results if the file opened..

fprintf(fileoutput, "Max Integer :%d ", maxvalue);

fprintf(fileoutput, "Min Integer :%d ", minvalue);

fprintf(fileoutput, "Sum :%d ", sum);

fprintf(fileoutput, "Average :%.2f ", average);

fprint(fileoutput, "Mode : %d ", Mode);

fprint(fileoutput, "median : %d ", median);

}

--------------------------------Add other functions for calculations here if that's neccessary.

int getMax(int arr[]) {

int i, maxvalue = arr[0];

for (i = 1; i < SIZE; i++) {

if (arr[i] > maxNumber) {

maxvalue = arr[i];

---- use printf to print data into new file. and please show a picture of it working if possible

}

}

return maxvalue;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!