C language learned by suffering
C language learned by suffering
Exercise 17
fundamental knowledge
Q1-1
What do you call a file in which only textual information is written?
Q 1-2
A file in which only numerical values are written
What do you call it in particular to distinguish it from the above files?
What do you call it in particular to distinguish it from the above files?
program read-only
When the following program is executed, what values will be written to what named file and in what format?
Q2-1
#include <stdio.h>
int main(void)
{
FILE* fp;
int dat[3] = { 10, 20, 30 }
fp = fopen("file.dat", "wb");
fwrite(&dat, sizeof(dat), 1, fp);
fclose(fp);
return 0;
}
program writing
number | Name | Average test score |
---|---|---|
1 | Nobi Nobita | 0 |
2 | source silence | 90 |
3 | Takeshi Tsuyoda | 40 |
4 | Suneo Bonegawa | 7 |
Q3-1
Create a program to create the above table in a format that can be opened in Excel.
Hint: CSV format can be opened in any spreadsheet software.
Hint: CSV format can be opened in any spreadsheet software.
descriptive expression
Q4-1
Information that should just be displayed on the display
Briefly explain why you bother to file.
Briefly explain why you bother to file.
Basic Knowledge (sample answers)
Solution 1-1
text file
Solution 1-2
binary file
Program reading (example solution)
Solution 2-1
The values 10, 20, and 30 are written in binary format to the file.dat file.
Program writing (example of solution)
Solution 3-1
#include <stdio.h>
int main(void)
{
FILE* fp;
fp = fopen("test.csv", "w");
fprintf(fp, "number,name,average test score\n");
fprintf(fp, "1,Nobita Nobi,0\n");
fprintf(fp, "2,Minamoto Shizuka,90\n");
fprintf(fp, "3,Takeshi Gouda,40\n");
fprintf(fp, "4,Suneo Konekawa,70,\n");
fclose(fp);
return 0;
}
*In this case, it is specified with a string literal, but if you are using an array or structure, even better.
*Points shall be deducted if the fclose function is forgotten.
Short Answer Type (Sample Answers)
Solution 4-1
Information on the screen disappears quickly, but
If it is a file, it can be stored semi-permanently and can be easily edited and passed on.
If it is a file, it can be stored semi-permanently and can be easily edited and passed on.
About this Site
The C language (bitter C), which is learned by suffering, is
This is the definitive C language introductory site.
It systematically explains the basic functions of the C language and
It is as complete as or more complete than any book on the market.