Programiranje Programski jezik C. Sadržaj. Datoteke. prof.dr.sc. Ivo Ipšić 2009/2010
|
|
- Job Moore
- 6 years ago
- Views:
Transcription
1 Programiranje Programski jezik C prof.dr.sc. Ivo Ipšić 2009/2010 Sadržaj Ulazno-izlazne funkcije Datoteke Formatirane datoteke Funkcije za rad s datotekama Primjeri Datoteke komunikacija između programa i okoline informacije o datotekama: mjesto zapisa datoteke na disku tip datoteke operacije nad datotekom pristup datotekama struktura tipa FILE, definirana u header datoteci stdio.h
2 Datoteke deklaracija pokazivača na datoteku FILE *ime_pok_na_datoteku; osnovne operacije otvaranje datoteke čitanje pisanje struktura FILE typedef struct char *buffer; /*pokazivac na adresu medjuspremnika */ char *ptr; /* pokazivac na slijedeci element */ int cnt; /* broj znakova u medjuspremniku */ int flags; /*parametri datoteke */ int fd; /* deskriptor datoteke */ FILE; Pristup podacima u datotekama pokazivač na međuspremnik pokazivač na slijedeći element broj znakova parametri datoteke deskriptor pisanje podataka pisanje podataka čitanje čitanje FILE *pok_na_dat; podataka podataka program međuspremnik datoteka
3 Datoteke fopen otvara datoteku FILE *fopen( const char *filename, const char *mode ); funkcija vraća pokazivač na otvorenu datoteku ili pokazivač tipa NULL mode r, w, a r čitanje w pisanje a dodavanje zapisa na kraj datoteke fclose zatvara datoteku int fclose( FILE *stream ); funkcija vraća 0 ukoliko je datoteka uspješno zatvorena int fcloseall(); funkcija fcloseall zatvara sve otvorene datoteke u programu čitanje i pisanje znakova fgetc čita znak iz datoteke int fgetc( FILE *stream ); stream pokazivač na strukturu tipa FILE funkcija vraća int pročitanog znaka ili znak EOF fputc piše znak u datoteku int fputc( int c, FILE *stream ); funkcija vraća int upisanog znaka
4 #include <stdio.h> #include <stdlib.h> void main() int broj_znakova=0; FILE *ulaz; int c; ulaz = fopen("text.txt","r"); if (ulaz == NULL) printf("datoteka ne postoji\n"); c = fgetc(ulaz); while (c!= EOF) broj_znakova++; c = fgetc(ulaz); fclose(ulaz); printf("broj znakova u datoteci: %d\n",broj_znakova); čitanje - fread int fread( void *buffer, int size, int count, FILE *stream ); vraća broj pročitanih jedinica, koji može biti manji od count ukoliko se je došlo do kraja datoteke count je broj jedinica koji se želi pročitati size je veličina jedne jedinice u bajtovima buffer je polje za zapis pročitanih jedinica stream je pokazivač na datoteku pisanje - fwrite intfwrite( const void *buffer, int size, int count, FILE *stream ); vraća broj zapisa count je broj jedinica koji se želi zapisati size je veličina jedne jedinice u bajtovima buffer je polje iz kojega se prenose podaci u datoteku stream je pokazivač na datoteku
5 čitanje - fread primjer čitanja jednog znaka while (!feof(ulaz)) fread(&c,sizeof(char),1,ulaz); broj_znakova++; funkcija feof vraća 0 ukoliko pokazivač ne pokazuje na kraj datoteke man feof 4.5 `feof'--test for end of file SYNOPSIS #include <stdio.h> int feof(file *FP); DESCRIPTION `feof' tests whether or not the end of the file identified by FP has been reached. RETURNS `feof' returns `0' if the end of file has not yet been reached; if at end of file, the result is nonzero. PORTABILITY `feof' is required by ANSI C. #include <stdio.h> #include <stdlib.h> void main() int broj_znakova=0; FILE *ulaz; int c; ulaz = fopen("text.txt","r"); if (ulaz == NULL) printf("datoteka ne postoji\n"); while (!feof(ulaz)) fread(&c,sizeof(char),1,ulaz); broj_znakova++; fclose(ulaz); printf("broj znakova u datoteci: %d\n",broj_znakova);
6 čitanje strukture struct osoba int sifra; char prez_ime[20+1]; unsigned int post_br; char adresa[30+1]; zaposlenik; fread(&zaposlenik,sizeof(struct osoba),1,fp); Primjer zapis podataka organiziranih u strukturu struct osoba int sifra; char prez_ime[20+1]; unsigned int post_br; char adresa[30+1]; ; struct osoba zaposlenik[100], zap_osoba; Primjer čitanje zapisa pomoću funkcije scanf i zapis strukture u datoteku for (i=0; i<br; i++) printf("upisi sifru osobe\n"); scanf("%2d", &zaposlenik[i].sifra); printf("upisi prezime osobe\n"); scanf("%s", zaposlenik[i].prez_ime); printf("osoba %2d: %s\n",zaposlenik[i].sifra, zaposlenik[i].prez_ime); fwrite(&zaposlenik[i],sizeof(struct osoba),1,izlaz);
7 #include <stdio.h> #include <stdlib.h> void main() struct osoba int sifra; char prez_ime[20+1]; unsigned int post_br; char adresa[30+1]; ; struct osoba zaposlenik[100], zap_osoba; int i, br; FILE *izlaz, *ulaz; printf("upisi broj osoba\n "); scanf("%d", &br); if ((izlaz= fopen("zap.txt","w")) == NULL) printf("datoteka se ne moze otvoriti\n"); for (i=0; i<br; i++) printf("upisi sifru osobe\n"); scanf("%2d", &zaposlenik[i].sifra); printf("upisi prezime osobe\n"); scanf("%s", zaposlenik[i].prez_ime); printf("osoba %2d: %s\n",zaposlenik[i].sifra, zaposlenik[i].prez_ime); fwrite(&zaposlenik[i],sizeof(struct osoba),1,izlaz); fclose(izlaz); if ((ulaz= fopen("zap.txt","r")) == NULL) printf("datoteka se ne moze otvoriti\n"); for (i=0; i<br; i++) fread(&zap_osoba,sizeof(struct osoba),1,ulaz); printf("%5d: %s\n",zap_osoba.sifra, zap_osoba.prez_ime); fclose(ulaz); /* kraj funkcije main*/ čitanje cijelog polja zaposlenik i ispis pojedinih elemenata struct osoba int sifra; char prez_ime[20+1]; unsigned int post_br; char adresa[30+1]; zaposlenik[100] ; fread(zaposlenik,sizeof(struct osoba),br,ulaz); for (i=0; i<br; i++) printf("%5d: %s\n", zaposlenik[i].sifra, zaposlenik[i].prez_ime);
8 Program čita znakove iz datoteke i izpisuje njihovu učestalost u datoteci. #include <stdio.h> #include <stdlib.h> main() struct znakovi int vrijednost_znaka; int ucestalost_znaka; ; struct znakovi frekvencije[256]; int i,broj_znakova=0; FILE *infile; int c; char datoteka[20]; printf("upisi ime datoteke\n"); scanf("%s",datoteka); infile = fopen(datoteka,"rb"); if (infile == NULL) printf("datoteka %s ne postoji\n",datoteka); for (i=0; i<256;i++) frekvencije[i].vrijednost_znaka=i; frekvencije[i].ucestalost_znaka=0; c = fgetc(infile); while (c!= EOF) broj_znakova++; if (c >= ' ') frekvencije[c].ucestalost_znaka++; c = fgetc(infile); fclose(infile); printf("%d znakova u datoteci\n",broj_znakova); for (i=0; i<256;i++) if (frekvencije[i].ucestalost_znaka!= 0) printf("%2c (%2d) = %d\n", i, frekvencije[i].vrijednost_znaka, frekvencije[i].ucestalost_znaka); Čitanje i pisanje znakovnih polja fgets char *fgets( char *string, intn, FILE*stream ); čita znakovno polje (string) maksimalne dužine n fputs int fputs( const char *string, FILE*stream ); #include <stdio.h> #include <stdlib.h> void main() int broj_redka=0; FILE *ulaz, *izlaz; int c; char buffer[255]; ulaz = fopen("text.txt","r"); if (ulaz == NULL) printf("datoteka ne postoji\n"); izlaz = fopen("text_novi.txt","w"); if (izlaz == NULL) printf("datoteka ne postoji\n"); while (fgets(buffer,255,ulaz)) fprintf(izlaz,"%3d %s\n",++broj_redka,buffer); fclose(ulaz); fclose(izlaz);
9 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 void main() 5 6 int broj_redka=0; 7 FILE *ulaz, *izlaz; 8 int c; 9 char buffer[255]; ulaz = fopen("text.txt","r"); 12 if (ulaz == NULL) 13 printf("datoteka ne postoji\n"); izlaz = fopen("text_novi.txt","w"); 17 if (izlaz == NULL) 18 printf("datoteka ne postoji\n"); while (fgets(buffer,255,ulaz)) 24 fprintf(izlaz,"%3d %s\n",++broj_redka,buffer); fclose(ulaz); 28 fclose(izlaz); Formatirane datoteke fprintf int fprintf( FILE *stream, const char *format [, argument ]...); fprintfvraća broj bajtova zapisanih u datoteku na koju pokazuje pokazivač stream Čitanje formatiranih datoteka fcanf int fscanf( FILE *stream, const char *format [, argument ]... ); funkcija fcanf vraća broj pročitanih elemenata primjer: float fp; char s[20]; FILE *pok_datoteke; fscanf( pok_datoteke, "%f", &fp ); fscanf( pok_datoteke, "%s", s );
10 Funkcije za rad s datotekama pomicanje - pozicioniranje u datoteci int fseek( FILE *stream, long offset, intorigin ); pomiće pokazivač offset bajtova u odnosu na origin SEEK_CUR Current position of file pointer SEEK_END End of file SEEK_SET Beginning of file long ftell( FILE *stream ); vraća položaj pokazivača u bajtovima
System Software Experiment 1 Lecture 7
System Software Experiment 1 Lecture 7 spring 2018 Jinkyu Jeong ( jinkyu@skku.edu) Computer Systems Laboratory Sungyunkwan University http://csl.skku.edu SSE3032: System Software Experiment 1, Spring 2018
More informationMode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.
Files Files enable permanent storage of information C performs all input and output, including disk files, by means of streams Stream oriented data files are divided into two categories Formatted data
More informationFile I/O. Arash Rafiey. November 7, 2017
November 7, 2017 Files File is a place on disk where a group of related data is stored. Files File is a place on disk where a group of related data is stored. C provides various functions to handle files
More informationENG120. Misc. Topics
ENG120 Misc. Topics Topics Files in C Using Command-Line Arguments Typecasting Working with Multiple source files Conditional Operator 2 Files and Streams C views each file as a sequence of bytes File
More informationCS240: Programming in C
CS240: Programming in C Lecture 13 si 14: Unix interface for working with files. Cristina Nita-Rotaru Lecture 13/Fall 2013 1 Working with Files (I/O) File system: specifies how the information is organized
More informationCSci 4061 Introduction to Operating Systems. Input/Output: High-level
CSci 4061 Introduction to Operating Systems Input/Output: High-level I/O Topics First, cover high-level I/O Next, talk about low-level device I/O I/O not part of the C language! High-level I/O Hide device
More informationFiles and Streams Opening and Closing a File Reading/Writing Text Reading/Writing Raw Data Random Access Files. C File Processing CS 2060
CS 2060 Files and Streams Files are used for long-term storage of data (on a hard drive rather than in memory). Files and Streams Files are used for long-term storage of data (on a hard drive rather than
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationAccessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts
Accessing Files in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter
More informationFile (1A) Young Won Lim 11/25/16
File (1A) Copyright (c) 2010-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationCSI 402 Lecture 2 Working with Files (Text and Binary)
CSI 402 Lecture 2 Working with Files (Text and Binary) 1 / 30 AQuickReviewofStandardI/O Recall that #include allows use of printf and scanf functions Example: int i; scanf("%d", &i); printf("value
More informationfopen() fclose() fgetc() fputc() fread() fwrite()
The ability to read data from and write data to files is the primary means of storing persistent data, data that does not disappear when your program stops running. The abstraction of files that C provides
More informationCMPE-013/L. File I/O. File Processing. Gabriel Hugh Elkaim Winter File Processing. Files and Streams. Outline.
CMPE-013/L Outline File Processing File I/O Gabriel Hugh Elkaim Winter 2014 Files and Streams Open and Close Files Read and Write Sequential Files Read and Write Random Access Files Read and Write Random
More informationFile IO and command line input CSE 2451
File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to
More informationStandard File Pointers
1 Programming in C Standard File Pointers Assigned to console unless redirected Standard input = stdin Used by scan function Can be redirected: cmd < input-file Standard output = stdout Used by printf
More informationInput/Output and the Operating Systems
Input/Output and the Operating Systems Fall 2015 Jinkyu Jeong (jinkyu@skku.edu) 1 I/O Functions Formatted I/O printf( ) and scanf( ) fprintf( ) and fscanf( ) sprintf( ) and sscanf( ) int printf(const char*
More informationIntroduction to file management
1 Introduction to file management Some application require input to be taken from a file and output is required to be stored in a file. The C language provides the facility of file input-output operations.
More informationa = ^ ^ ^ ^ ^ ^ ^ b = c = a^b =
a = b = ^ ^ ^ ^ ^ ^ ^ ^ c=a^b= & a&b a b ^ a^b &= a &= b = a = b ^= a ^= b >b >>= a >>= b
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 INPUT/OUTPUT INPUT AND OUTPUT Programs must be able to write data to files or to physical output devices such as displays or printers, and to read in data from files or
More informationComputer System and programming in C
File Handling 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 storage so that the contents of files remain intact
More informationStandard C Library Functions
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationLecture 9: File Processing. Quazi Rahman
60-141 Lecture 9: File Processing Quazi Rahman 1 Outlines Files Data Hierarchy File Operations Types of File Accessing Files 2 FILES Storage of data in variables, arrays or in any other data structures,
More informationC File Processing: One-Page Summary
Chapter 11 C File Processing C File Processing: One-Page Summary #include int main() { int a; FILE *fpin, *fpout; if ( ( fpin = fopen( "input.txt", "r" ) ) == NULL ) printf( "File could not be
More informationContent. Input Output Devices File access Function of File I/O Redirection Command-line arguments
File I/O Content Input Output Devices File access Function of File I/O Redirection Command-line arguments UNIX and C language C is a general-purpose, high-level language that was originally developed by
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 12
BIL 104E Introduction to Scientific and Engineering Computing Lecture 12 Files v.s. Streams In C, a file can refer to a disk file, a terminal, a printer, or a tape drive. In other words, a file represents
More informationComputer programming
Computer programming "He who loves practice without theory is like the sailor who boards ship without a ruder and compass and never knows where he may cast." Leonardo da Vinci T.U. Cluj-Napoca - Computer
More informationCSI 402 Systems Programming LECTURE 4 FILES AND FILE OPERATIONS
CSI 402 Systems Programming LECTURE 4 FILES AND FILE OPERATIONS A mini Quiz 2 Consider the following struct definition struct name{ int a; float b; }; Then somewhere in main() struct name *ptr,p; ptr=&p;
More informationUNIT IV-2. The I/O library functions can be classified into two broad categories:
UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known
More informationEM108 Software Development for Engineers
EE108 Section 4 Files page 1 of 14 EM108 Software Development for Engineers Section 4 - Files 1) Introduction 2) Operations with Files 3) Opening Files 4) Input/Output Operations 5) Other Operations 6)
More informationDarshan Institute of Engineering & Technology for Diploma Studies Unit 6
1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard
More informationInput / Output Functions
CSE 2421: Systems I Low-Level Programming and Computer Organization Input / Output Functions Presentation G Read/Study: Reek Chapter 15 Gojko Babić 10-03-2018 Input and Output Functions The stdio.h contain
More informationC Basics And Concepts Input And Output
C Basics And Concepts Input And Output Report Working group scientific computing Department of informatics Faculty of mathematics, informatics and natural sciences University of Hamburg Written by: Marcus
More informationCS246 Spring14 Programming Paradigm Files, Pipes and Redirection
1 Files 1.1 File functions Opening Files : The function fopen opens a file and returns a FILE pointer. FILE *fopen( const char * filename, const char * mode ); The allowed modes for fopen are as follows
More informationUNIX System Programming
File I/O 경희대학교컴퓨터공학과 조진성 UNIX System Programming File in UNIX n Unified interface for all I/Os in UNIX ü Regular(normal) files in file system ü Special files for devices terminal, keyboard, mouse, tape,
More informationData File and File Handling
Types of Disk Files Data File and File Handling Text streams are associated with text-mode files. Text-mode files consist of a sequence of lines. Each line contains zero or more characters and ends with
More informationC PROGRAMMING. Characters and Strings File Processing Exercise
C PROGRAMMING Characters and Strings File Processing Exercise CHARACTERS AND STRINGS A single character defined using the char variable type Character constant is an int value enclosed by single quotes
More informationFile Processing. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan
File Processing Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline 11.2 The Data Hierarchy 11.3 Files and Streams 11.4 Creating a Sequential
More informationChapter 12. Files (reference: Deitel s chap 11) chap8
Chapter 12 Files (reference: Deitel s chap 11) 20061025 chap8 Introduction of File Data files Can be created, updated, and processed by C programs Are used for permanent storage of large amounts of data
More informationC-Refresher: Session 10 Disk IO
C-Refresher: Session 10 Disk IO Arif Butt Summer 2017 I am Thankful to my student Muhammad Zubair bcsf14m029@pucit.edu.pk for preparation of these slides in accordance with my video lectures at http://www.arifbutt.me/category/c-behind-the-curtain/
More informationCS1003: Intro to CS, Summer 2008
CS1003: Intro to CS, Summer 2008 Lab #07 Instructor: Arezu Moghadam arezu@cs.columbia.edu 6/25/2008 Recap Pointers Structures 1 Pointer Arithmetic (exercise) What do the following return? given > char
More informationFile Handling. Reference:
File Handling Reference: http://www.tutorialspoint.com/c_standard_library/ Array argument return int * getrandom( ) static int r[10]; int i; /* set the seed */ srand( (unsigned)time( NULL ) ); for ( i
More informationSystems Programming. 08. Standard I/O Library. Alexander Holupirek
Systems Programming 08. Standard I/O Library Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of Konstanz Summer Term 2008 Last lecture:
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.
C How to Program, 6/e Storage of data in variables and arrays is temporary such data is lost when a program terminates. Files are used for permanent retention of data. Computers store files on secondary
More informationCSI 402 Lecture 2 (More on Files) 2 1 / 20
CSI 402 Lecture 2 (More on Files) 2 1 / 20 Files A Quick Review Type for file variables: FILE * File operations use functions from stdio.h. Functions fopen and fclose for opening and closing files. Functions
More informationChapter 12. Text and Binary File Processing. Instructor: Öğr. Gör. Okan Vardarlı. Copyright 2004 Pearson Addison-Wesley. All rights reserved.
Chapter 12 Text and Binary File Processing Instructor: Öğr. Gör. Okan Vardarlı Copyright 2004 Pearson Addison-Wesley. All rights reserved. Objectives We will explore the use of standard input, standard
More informationNaked C Lecture 6. File Operations and System Calls
Naked C Lecture 6 File Operations and System Calls 20 August 2012 Libc and Linking Libc is the standard C library Provides most of the basic functionality that we've been using String functions, fork,
More informationC for Engineers and Scientists: An Interpretive Approach. Chapter 14: File Processing
Chapter 14: File Processing Files and Streams C views each file simply as a sequential stream of bytes. It ends as if there is an end-of-file marker. The data structure FILE, defined in stdio.h, stores
More informationCh 11. C File Processing (review)
Ch 11 C File Processing (review) OBJECTIVES To create, read, write and update files. Sequential access file processing. Data Hierarchy Data Hierarchy: Bit smallest data item Value of 0 or 1 Byte 8 bits
More information2009 S2 COMP File Operations
2009 S2 COMP1921 9. File Operations Oliver Diessel odiessel@cse.unsw.edu.au Last updated: 16:00 22 Sep 2009 9. File Operations Topics to be covered: Streams Text file operations Binary file operations
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More informationWhat Is Operating System? Operating Systems, System Calls, and Buffered I/O. Academic Computers in 1983 and Operating System
What Is Operating System? Operating Systems, System Calls, and Buffered I/O emacs gcc Browser DVD Player Operating System CS 217 1 Abstraction of hardware Virtualization Protection and security 2 Academic
More informationC mini reference. 5 Binary numbers 12
C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char
More informationC programming basics T3-1 -
C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of
More informationFile I/O. Preprocessor Macros
Computer Programming File I/O. Preprocessor Macros Marius Minea marius@cs.upt.ro 4 December 2017 Files and streams A file is a data resource on persistent storage (e.g. disk). File contents are typically
More informationC Programming Language
C Programming Language File Input/Output Dr. Manar Mohaisen Office: F208 Email: manar.subhi@kut.ac.kr Department of EECE Review of the Precedent Lecture Arrays and Pointers Class Objectives What is a File?
More informationUnit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character
1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard
More informationComputer Programming Unit v
READING AND WRITING CHARACTERS We can read and write a character on screen using printf() and scanf() function but this is not applicable in all situations. In C programming language some function are
More informationMARKS: Q1 /20 /15 /15 /15 / 5 /30 TOTAL: /100
FINAL EXAMINATION INTRODUCTION TO ALGORITHMS AND PROGRAMMING II 03-60-141-01 U N I V E R S I T Y O F W I N D S O R S C H O O L O F C O M P U T E R S C I E N C E Winter 2014 Last Name: First Name: Student
More information8. Structures, File I/O, Recursion. 18 th October IIT Kanpur
8. Structures, File I/O, Recursion 18 th October IIT Kanpur C Course, Programming club, Fall 2008 1 Basic of Structures Definition: A collection of one or more different variables with the same handle
More informationM.CS201 Programming language
Power Engineering School M.CS201 Programming language Lecture 16 Lecturer: Prof. Dr. T.Uranchimeg Agenda Opening a File Errors with open files Writing and Reading File Data Formatted File Input Direct
More informationLecture6 File Processing
1 Lecture6 File Processing Dr. Serdar ÇELEBİ 2 Introduction The Data Hierarchy Files and Streams Creating a Sequential Access File Reading Data from a Sequential Access File Updating Sequential Access
More information25.2 Opening and Closing a File
Lecture 32 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 32: Dynamically Allocated Arrays 26-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor:
More informationIntroduction to Computer Programming Lecture 18 Binary Files
Introduction to Computer Programming Lecture 18 Binary Files Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical&Electronics Engineering nukhet.ozbek@ege.edu.tr 1 RECALL: Text File Handling
More informationIntroduction to Computer and Program Design. Lesson 6. File I/O. James C.C. Cheng Department of Computer Science National Chiao Tung University
Introduction to Computer and Program Design Lesson 6 File I/O James C.C. Cheng Department of Computer Science National Chiao Tung University File System in OS Microsoft Windows Filename DriveID : /DirctoryName/MainFileName.ExtensionName
More informationLecture 8. Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)
Lecture 8 Data Files Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To be able to create, read, write and update
More informationSystem Programming. Standard Input/Output Library (Cont d)
Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Binary I/O 2 3 4 5 Binary
More informationStandard I/O in C, Computer System and programming in C
Standard I/O in C, Contents 1. Preface/Introduction 2. Standardization and Implementation 3. File I/O 4. Standard I/O Library 5. Files and Directories 6. System Data Files and Information 7. Environment
More informationChapter 11 File Processing
1 Chapter 11 File Processing Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 11 File Processing Outline 11.1 Introduction 11.2 The Data Hierarchy 11.3
More informationMemory Management and
Introduction to Computer and Program Design Lesson 6 Memory Management and File I/O James C.C. Cheng Department of Computer Science National Chiao Tung University Dynamic memory allocation l malloc Syntax:
More informationMain Program Revisited. Reading Assignment. K.N. King Chapter 3, 22. K.N. King Sections Example of Argument Processing
Reading Assignment Main Program Revisited void main( int argc, char * argv[] ) K.N. King Chapter 3, 22 K.N. King Sections 13.7 argc is the number of command line arguments that have been passed to the
More informationSTRUCTURES & FILE IO
STRUCTURES & FILE IO Structures Collections of related variables (aggregates) under one name Can contain variables of different data types Commonly used to define records to be stored in files Combined
More informationHIGH LEVEL FILE PROCESSING
HIGH LEVEL FILE PROCESSING 1. Overview The learning objectives of this lab session are: To understand the functions used for file processing at a higher level. o These functions use special structures
More informationA stream is infinite. File access methods. File I/O in C++ 4. File input/output David Keil CS II 2/03. The extractor and inserter form expressions
Topic: File input/output I. Streams II. Access methods III. C++ style Input, output, random access Stream classes: ifstream, ofstream IV. C style The FILE data type Opening files Writing to, reading text
More informationUNIT-V CONSOLE I/O. This section examines in detail the console I/O functions.
UNIT-V Unit-5 File Streams Formatted I/O Preprocessor Directives Printf Scanf A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage
More informationFundamentals of Programming. Lecture 10 Hamed Rasifard
Fundamentals of Programming Lecture 10 Hamed Rasifard 1 Outline File Input/Output 2 Streams and Files The C I/O system supplies a consistent interface to the programmer independent of the actual device
More informationCE Lecture 11
Izmir Institute of Technology CE - 104 Lecture 11 References: - C: A software Engineering Approach 1 In this course you will learn Input and Output Sorting Values 2 Input and Output Opening and Closing
More informationCS240: Programming in C
CS240: Programming in C Lecture 15: Unix interface: low-level interface Cristina Nita-Rotaru Lecture 15/Fall 2013 1 Streams Recap Higher-level interface, layered on top of the primitive file descriptor
More informationQuick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.
1 Quick review of previous lecture Ch6 Structure Ch7 I/O EECS2031 Software Tools C - Structures, Unions, Enums & Typedef (K&R Ch.6) Structures Basics: Declaration and assignment Structures and functions
More informationPrinceton University Computer Science 217: Introduction to Programming Systems. I/O Management
Princeton University Computer Science 7: Introduction to Programming Systems I/O Management Goals of this Lecture Help you to learn about: The C/Unix file abstraction Standard C I/O Data structures & functions
More informationPrinceton University. Computer Science 217: Introduction to Programming Systems. I/O Management
Princeton University Computer Science 7: Introduction to Programming Systems I/O Management Goals of this Lecture Help you to learn about: The C/Unix file abstraction Standard C I/O Data structures & functions
More informationIO = Input & Output 2
Input & Output 1 IO = Input & Output 2 Idioms 3 Input and output in C are simple, in theory, because everything is handled by function calls, and you just have to look up the documentation of each function
More informationUNIT- 2. Binary File
UNIT- 2 Binary Files Structure: 2.1 Classification Of Files 2.2 Files Modes 2.3 Standard Library Functions for Files 2.4 File Type Conversion 2.1 Classification Of Files A file is collection of data. A
More informationCS 261 Fall Mike Lam, Professor. Structs and I/O
CS 261 Fall 2018 Mike Lam, Professor Structs and I/O Typedefs A typedef is a way to create a new type name Basically a synonym for another type Useful for shortening long types or providing more meaningful
More informationPrinceton University Computer Science 217: Introduction to Programming Systems I/O Management
Princeton University Computer Science 7: Introduction to Programming Systems I/O Management From a student's readme: ====================== Stress Testing ====================== To stress out this program,
More informationGoals of this Lecture
I/O Management 1 Goals of this Lecture Help you to learn about: The Unix stream concept Standard C I/O functions Unix system-level functions for I/O How the standard C I/O functions use the Unix system-level
More informationI/O Management! Goals of this Lecture!
I/O Management! 1 Goals of this Lecture! Help you to learn about:" The Unix stream concept" Standard C I/O functions" Unix system-level functions for I/O" How the standard C I/O functions use the Unix
More informationI/O Management! Goals of this Lecture!
I/O Management! 1 Goals of this Lecture! Help you to learn about:" The Unix stream concept" Standard C I/O functions" Unix system-level functions for I/O" How the standard C I/O functions use the Unix
More informationLAB 13 FILE PROCESSING
LAB 13 FILE PROCESSING School of Computer and Communication Engineering Universiti Malaysia Perlis 1 1. OBJECTIVES: 1.1 To be able to create, read, write and update files. 1.2 To become familiar with sequential
More informationUNIX Shell. The shell sits between you and the operating system, acting as a command interpreter
Shell Programming Linux Commands UNIX Shell The shell sits between you and the operating system, acting as a command interpreter The user interacts with the kernel through the shell. You can write text
More informationmywbut.com 12 File Input/Output
12 File Input/Output Data Organization File Operations Opening a File Reading from a File Trouble in Opening a File Closing the File Counting Characters, Tabs, Spaces, A File-copy Program Writing to a
More informationCSE2301. Introduction. Streams and Files. File Access Random Numbers Testing and Debugging. In this part, we introduce
Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who
More informationLANGUAGE OF THE C. C: Part 6. Listing 1 1 #include <stdio.h> 2 3 int main(int argc, char *argv[]) PROGRAMMING
C: Part 6 LANGUAGE OF THE C In part 6 of Steve Goodwins C tutorial we continue our look at file handling and keyboard input File handling Most software will at some time need to read from (or perhaps write
More informationData Files. Computer Basics
Unit 10 Data Files Computer Basics Contents What is a data file? Basic operations with data files: Opening a data file Closing a data file Types of data files Text Files Reading text files Writing text
More informationProgramming Fundamentals
Programming Fundamentals Day 4 1 Session Plan Searching & Sorting Sorting Selection Sort Insertion Sort Bubble Sort Searching Linear Search Binary Search File Handling Functions Copyright 2004, 2 2 Sorting
More informationCopyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented
More informationOrganization of a file
File Handling 1 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example: Consider keeping students records 100 students
More informationLAB 13 FILE PROCESSING
LAB 13 FILE PROCESSING School of Computer and Communication Engineering Universiti Malaysia Perlis 1 1. OBJECTIVES: 1.1 To be able to create, read, write and update files. 1.2 To become familiar with sequential
More informationPreprocessing directives are lines in your program that start with `#'. The `#' is followed by an identifier that is the directive name.
Unit-III Preprocessor: The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it
More informationComputer Language. It is a systematical code for communication between System and user. This is in two categories.
ComputerWares There are 3 types of Computer wares. 1. Humanware: The person, who can use the system, is called 'Human Ware ". He is also called as "User". Users are in two types: i. Programmer: The person,
More informationC: How to Program. Week /June/18
C: How to Program Week 17 2007/June/18 1 Chapter 11 File Processing Outline 11.1 Introduction 11.2 The Data Hierarchy 11.3 Files and Streams 11.4 Creating a Sequential Access File 11.5 Reading Data from
More information