The file below, wine.txt, contains the records from a wine data file. wine.txt T
ID: 3777240 • Letter: T
Question
The file below, wine.txt, contains the records from a wine data file.
wine.txt
The 5 fields in each row are:
The wine identification number
Wine name
Type of wine (2=Sparkling, 3=Fortified, 4=Sweet, 5=White, 6=Red)
Year wine was made
Winery Number
This assignment requires that you create a report that will print the number of wines by type.
The report should have a proper heading that includes a main heading
The main heading should include the current date
The report heading should also have column headings for the type of wine and total (for the total of each type of wine)
The record output should be formatted to display the data (wine type and count) below each column header
The report should print on a "clean screen"
Explanation / Answer
#include #include // For exit() function int main() { char c[1000]; FILE *fptr; if ((fptr = fopen("program.txt", "r")) == NULL) { printf("Error! opening file"); // Program exits if file pointer returns NULL. exit(1); } // reads text until newline fscanf(fptr,"%[^ ]", c); printf("Data from the file: %s", c); fclose(fptr); return 0; } char str[999]; FILE * file; file = fopen( "test.txt" , "r"); if (file) { while (fscanf(file, "%s", str)!=EOF) printf("%s",str); fclose(file); }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.