Manipulating File IO in Visual C++

Slides:



Advertisements
Similar presentations
File Management in C. What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary.
Advertisements

BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
Files in C Rohit Khokher. Files in C Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two.
Chapter 11: Data Files & File Processing In this chapter, you will learn about Files and streams Creating a sequential access file Reading data from a.
FILES Files types and operations. Files Files are used to store data Data can be Text (ASCII only: 0  127) Binary (Full range: 0  256) Each file resides.
CSCI 171 Presentation 12 Files. Working with files File Streams – sequence of data that is connected with a specific file –Text Stream – Made up of lines.
Structures and Unions Chapter 6. Structure A structure is an aggregate data type  Composed of two or more related variables called member/field/element.
File I/O.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
N305: C Programming Copyright ©2006  Department of Computer & Information Science File Handling in C.
Lone Leth Thomsen Input / Output and Files. April 2006Basis-C-8/LL2 sprintf() and sscanf() The functions sprintf() and sscanf() are string versions of.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
22. FILE INPUT/OUTPUT. File Pointers and Streams Declarations of functions that perform file I/O appear in. Each function requires a file pointer as a.
File Handling In C By - AJAY SHARMA. We will learn about- FFile/Stream TText vs Binary Files FFILE Structure DDisk I/O function OOperations.
Introduction to Programming Using C Files. 2 Contents Files Working with files Sequential files Records.
File IO and command line input CSE 2451 Rong Shi.
Chapter 8 File-Oriented Input and Output. 8.1 INTRODUCTION a file can also be designed to store data. We can easily update files, A data file as input.
CSEB114: Principle of programming Chapter 11: Data Files & File Processing.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
1 Lecture09: File I/O 11/19/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
CNG 140 C Programming (Lecture set 10) Spring Chapter 10 Data Files.
24-2 Perform File I/O using file pointers FILE * data-type Opening and closing files Character Input and Output String Input and Output Related Chapter:
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
ME-2221 COMPUTER PROGRAMMING Lecture 18 FILE OPERATIONS Department of Mechanical Engineering A.H.M Fazle Elahi Khulna University of engineering & Technology.
1 CSC103: Introduction to Computer and Programming Lecture No 28.
1 CSC103: Introduction to Computer and Programming Lecture No 27.
Files A collection of related data treated as a unit. Two types Text
CSCI N305: C Programming Copyright ©2006  Department of Computer & Information Science File Handling in C.
FILES IN C. File Operations  Creation of a new file  Opening an existing file  Reading from a file  Writing to a file  Moving to a specific location.
Files. FILE * u In C, we use a FILE * data type to access files. u FILE * is defined in /usr/include/stdio.h u An example: #include int main() { FILE.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
ECE Application Programming
Chapter 4 File Processing
RECURSION Recursion is a process where a function calls itself. main()
Lecture 11 File input/output
File Access (7.5) CSE 2031 Fall July 2018.
Introduction to Computer Programming Lecture 18 Binary Files
File I/O.
File Input/Output.
What you need for the 1st phase of project
File I/O We are used to reading from and writing to the terminal:
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
Input/Output and the Operating Systems
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
FILE HANDLING IN C.
Text and Binary File Processing
File Input and Output.
File Handling.
File Access (7.5) CSE 2031 Fall January 2019.
Accessing Files in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
The Problems in Using Visual C and Homework #2 Assignment
File Access (7.5) CSE 2031 Fall February 2019.
Introduction to Debugging Techniques in Visual C++ 6.0
Strings and Pointer Arrays
Files.
C Preprocessing File I/O
Building Windows Applications by Visual C++ and Homework #3 Assignment
FILE handeling.
Module 12 Input and Output
EECE.2160 ECE Application Programming
CSc 352 File I/O Saumya Debray Dept. of Computer Science
EECE.2160 ECE Application Programming
Message Mapping Mechanisms in MFC and Other Applications in Visual C++
Professor Jodi Neely-Ritz University of Florida
File I/O We are used to reading from and writing to the terminal:
Files Chapter 8.
Presentation transcript:

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

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.

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

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.

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.

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

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.

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