Presentation is loading. Please wait.

Presentation is loading. Please wait.

Manipulating File IO in Visual C++

Similar presentations


Presentation on theme: "Manipulating File IO in Visual C++"— Presentation transcript:

1 Manipulating File IO in Visual C++
Speaker: Yao-Ting Huang Advisor: Kun-Mao Chao National Taiwan University Department of Computer Science & Information Engineering Algorithms and Computational Biology Lab. 2018/11/24

2 Standard IO Manipulating Functions
You have to include <stdio.h>. You have to use the file pointer. #include <stdio.h> File *fp; fp = fopen(“myfile.txt”, “w”); fprintf(fp,”Hello!”); fclose(fp); The fopen function requests OS for a memory buffer. Your program actually reads/writes to the buffer, and the OS controls the trasmission between the buffer and disk.

3 Standard IO Manipulating Functions
The fclose function flushes the remaining contents in the buffer and release the pointer and buffer. The maximum number of opened file pointers are depending on OS. Write Write Disk C Program Memory Buffer Read Read

4 Standard IO Manipulating Functions
The syntax of fopen File* fopen(char *filename, char *mode); mode: “r”, “w”, “a”, “r+”, “w+b”, …etc. If the file can not be open or created, the fopen function returns 0 (NULL). Other file manipulating functions: fscanf and fprintf: formatted input/output file functions. fgetc, fputc: get or put a single char from or into a file. fgets, fputs: get or out a string from or into a file. See an example.

5 Homework #4 (1/3) Write a program that prompts the user to input an integer n. Draw a triangle with n levels, and each level has n star symbols. For example, n = 3, * * * * * * After drawing the triangle, repeat the above process until the user inputs a negative integer.

6 Homework #4 (2/3) An usage scenario:
Please input: 2 * * * Please input: 3 * * * * * * Please input: -9 Thank you for using this program.

7 Homework #4 (3/3) You can draw other shapes to get bonus.
e.g., n=3 (triangle) * * * * * * e.g., n=3 (reverse triangle) * * * * * * Due date: 11/18.

8 Outline of Lecture Today
A C file application. Demo of your Homework #3. Please make sure your program is ready to execute.


Download ppt "Manipulating File IO in Visual C++"

Similar presentations


Ads by Google