MMGameslogo  MMGames
TwitterSharebutton  FacebookSharebutton   
learn through sufferingC Language
learn through sufferingC Language

Practice Problem 17

Fundamentals

Question 1-1
What do you call a file that contains only textual information?


Question 1-2
numericsのみが書き込まれたFileを
上記のFileと区別してとくになんと呼ぶか。

Program reading
"When this program is executed, what is the name of the file that will be written to, in what format, and with what values?"

Question 2-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 Manual

番号 名前 テストの平均点
1 野比のびBold 0
2 源静香 90
3 剛田武 40
4 骨川スネ夫 7


Question 3-1
Please create a program that generates the above table in a format that can be opened in Excel.
Hint: CSV files can be opened with any spreadsheet software.


descriptive

Question 4-1
ディスプレイに表示すれば良いはずの情報を、
わざわざFileにするのはなぜか簡潔に述べよ。

Fundamentals (Answer Key)

Solution 1-1
text file


Solution 1-2
Binary file

Program Reading (Solution Example)

Solution 2-1
The values 10, 20, and 30 are written in binary format to the file.dat file.

Program Documentation (Example Solution)

Solution 3-1
#include <stdio.h>

int main(void)
{
    FILE* fp;

    fp = fopen("test.csv", "w");

    fprintf(fp, "番号,名前,テストの平均点\n");
    fprintf(fp, "1,野比のびBold,0\n");
    fprintf(fp, "2,源静香,90\n");
    fprintf(fp, "3,剛田武,40\n");
    fprintf(fp, "4,骨川スネ夫,70,\n");

    fclose(fp);

    return 0;
}

"While we're using string literals here, it would be even better if you were using arrays or structs."
"Points will be deducted if you forget to use the fclose function."
descriptive (answer)

Solution 4-1
Screenに表示した情報はすぐに消えてしまうが、
If you save it as a file, it can be stored almost indefinitely and is easy to edit and share.



About This Site

Learning C language through suffering (Kushi C) is
This is the definitive introduction to the C language.
It systematically explains the basic functions of the C language.
The quality is equal to or higher than commercially available books.

Part 0: Program Overview
  1. What is a program?
Chapter 3: Displaying on the Screen
  1. String Display
  2. newline character
  3. Practice Problem 3
Chapter 4: Displaying and Calculating Numbers
  1. Display of numbers
  2. Basic calculations
  3. Numeric types
  4. Practice Problem 4
Chapter 6: Input from the Keyboard
  1. input function
  2. The fear of input
  3. Practice Problem 6
Chapter 9: Repeating a Fixed Number of Times
  1. Iterative sentence
  2. How Loops Work
  3. Practice Problem 9
Chapter 10: Repeating Without Knowing the Number of Times
  1. Unspecified loop
  2. Input validation
  3. Practice Problem 10
Chapter 13: Handling Multiple Variables at Once
  1. Handling multiple variables collectively.
  2. Arrays
  3. Practice Problem 13
Chapter 19: Dynamic Arrays
  1. Create arrays freely.
  2. Practice Problem 19