Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads a file and summarizes the data in C using c89. hard-c

ID: 664629 • Letter: W

Question

Write a program that reads a file and summarizes the data in C using c89.

hard-code the filename data03.txt in your program and read this file exactly once. •

Each time you run the data generator you will get a different file.

You program will read data03.txt and produce the sum of each column, grouped by letter of the alphabet that the names begin with. The results should be printed, sorted by letter of the alphabet in ascending order. Letters of the alphabet that were not present as the first letter of any names in the data should not be printed.

• We know the following about the contents of data03.txt, which we can use in our programs:

– data03.txt is an example of a fixed-width text file.

– Columns 1–10 contain a string of a person’s name.

– Columns 12-15 contain an integer in the range of -100 to 100.

– Columns 17-20 contain an integer in the range of -100 to 100.

– Each letter’s sum will be in the range of ±999. – There is one blank space between each column.

– The names are capitalized, that is, the first character is uppercase.

– The names are unknown and can vary. – The number of lines is unknown and can vary. – We are still aware of the ASCII table and that there are 26 uppercase characters

Explanation / Answer

#include void main() { FILE *fptr; char name[20]; int age; float salary; /* open for writing */ fptr = fopen("emp.rec", "w"); if (fptr == NULL) { printf("File does not exists "); return; } printf("Enter the name "); scanf("%s", name); fprintf(fptr, "Name = %s ", name); printf("Enter the age "); scanf("%d", &age); fprintf(fptr, "Age = %d ", age); printf("Enter the salary "); scanf("%f", &salary); fprintf(fptr, "Salary = %.2f ", salary); fclose(fptr); }