Manipulating File IO in Visual C - PowerPoint PPT Presentation

About This Presentation
Title:

Manipulating File IO in Visual C

Description:

Department of Computer Science & Information Engineering ... You have to include stdio.h . You have to use the file pointer. #include stdio.h ... – PowerPoint PPT presentation

Number of Views:12
Avg rating:3.0/5.0
Slides: 9
Provided by: chi115
Category:

less

Transcript and Presenter's Notes

Title: Manipulating File IO in Visual C


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.
2
Standard IO Manipulating Functions
  • You have to include ltstdio.hgt.
  • You have to use the file pointer.
  • include ltstdio.hgtFile fpfp
    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
Memory Buffer
C Program
Read
Read
4
Standard IO Manipulating Functions
  • The syntax of fopen
  • File fopen(char filename, char mode)
  • mode r, w, a, r, wb, 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 -9Thank you for using this
    program.

7
Homework 4 (3/3)
  • You can draw other shapes to get bonus.
  • e.g., n3 (triangle)
  • e.g., n3 (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.
Write a Comment
User Comments (0)
About PowerShow.com