Lab15File1. Purpose1) Grasp the concept of file, buffer file system and file structure pointer.2) Grasp the specific steps of document operation.3) Learning how to use files to open, close, read, write and other file operation functions.4) Learninghow to use the buffer file system to do some simple operations on files. 2. Required Tasks1) Read the following program, analyze the contents ,what is the content of the file filetest.txt?#include #include void fun(char *fname,char *st){FILE *myf;int i;myf=fopen(fname,"w");if (st==NULL)return;for(i=0;ivoid main(){FILE *fp;char ch,fname[32];int count=0;printf("Input the filename:");scanf("%s",fname);if((fp=fopen( ⑴ ,"w+"))==NULL){printf("Cant open file:%s\n",fname);exit(0);}printf("Enter data:\n");while((ch=getchar())!=#){fputc(ch,fp);count++;}fprintf( ⑵ ,"\n%d\n",count);fcolse(fp);} 3) Input 10 character strings from the keyboard, change the lowercase to uppercase, and then output to a disk file "test. Dat" , then reading the string from the file and displaying. Use fputc, fprintf,fputs to write to file respectively; Use fgetc, fscanf, fgets to read from file respectively.4) Write a program, Test writing 10 floats into a text file (w a r+ w+ modes and fputs()/fprintf() ) and a binary file(b mode and fwrite()) respectively. Open the two files again, display the floats. 5) Define a structure to store a row of data in the following table, and store the data of the entire table within a linked list.
AnthonyA.J.100317.8262/12/18BurrowsW.K.100679.1463/6/9FainB.D.100838.7959/5/18JanneyP.1009510.5762/9/28SmithG.J.101058.5091/12/20 Write a program, enter the above data to the structure list (linked list), and store data into a text file. Then read out the contents of the above file into a linked list(define the corresponding structure type), display the list on the screen.Use fwrite() and fread() functions. 3. Optional Tasks1) Read the following procedures and C program, and fill in the blanks. This program finds all the integers in the text file "st.dat". In the text file, the integers are separated by space characters, Tab characters (tab characters) and carriage returns. The program uses array b[] to store different integers, the variable K is the number of different integers stored in the array B, and assumes that the number of different integers in the file is not more than 1000. Procedures are as follows:#include #define N 1000void main(){FILE ⑴ ;int b[N],d,i,k;if ((fpt= ⑵ ==NULL){printf("Can not open file st.dat.\n");return;}k=0;while(fscanf( ⑶ )==1){b[k]=d;for(i=0;b[i]!=d;i++);if( ⑷ ) k++;}(5) ;for(i=0;i#include #include char class_list[]="EIMQUZ";int q_list[26],q;FILE *fopen(), *fp;void main(){char file_name[120],pname[20];int i,sp;char sch;printf("Input data file name.");scanf("%s",file_name);if((fp=fopen(file_name,"r"))==NULL){printf("Can not open file %s\n",file_name);exit⑴;}for(i=0;i=apname[0]0) printf("%c--%c:%d\n",sch,class_list[i],q_list[i]);sch=class_list[i]+1;}} 3) There are five students, each of them has three courses and input data (including the number of students, name, three courses grades) from the keyboard and make a linked list to store them. Calculate the average score, and save the 5 students’ data (5 structure variables) and their calculated average scores in the disk file "stud. Dat". Write another program to open the file, read the data in file and store them in a linked list (it’s to restore the linked list) , display the 5 students’ data and their average score. 4) Write a program to save the following data to a text file.5 96 87 78 93 21 4 92 82 85 87 6 72 69 85 75 81 73At the same time, the average number of each group in the above data is calculated and displayed in the program. The data is arranged in a file: the number that represents each group is placed in front of the group. For example, the first number 5 in the document indicates that the next 5 numbers will be grouped together. The number 4 indicates the following 4 numbers are a group, and the 6 represents the last 6 numbers as a group. 5) Write a program, create a binary file of grades.bin, and write the following 5 rows of data to the file.90.3 92.7 90.3 99.885.3 90.5 87.3 90.893.2 88.4 93.8 75.682.4 95.6 78.2 90.093.5 80.2 92.9 94.4At the same time, read the four data (scores) of each line in the program, calculate and display the average of each group (average score). 4. Experimental ResultWrite an experiment report, it includes:1) The running results and source programs of required subjects.2) The running results and source programs of chosen subjects.3) The error information when debugging(both in English and Chinese).4) If there are some programs can not compile/link/run, please analysis the reasons.