Internship in DASAN networks C programing language Chapter 7 : Input and Output Present by Le Thi Hien 1/14.

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 7 Semantics Surely all this is not without.
Advertisements

Files Used to transfer data to and from disk. Opening an Output File Stream #include // File stream library. ofstream outfile;// Declare file stream variable.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 14 - Advanced C Topics Outline 14.1Introduction 14.2Redirecting Input/Output on UNIX and DOS Systems.
UNIT 15 File Processing.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
UNIX Chapter 12 Redirection and Piping Mr. Mohammad Smirat.
Input from STDIN STDIN, standard input, comes from the keyboard. STDIN can also be used with file re-direction from the command line. For instance, if.
1 Text File I/O Chapter 6 Pages File I/O in an Object-Oriented Language Compare to File I/O in C. Instantiate an ofstream object. Like opening.
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.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 12  File Input and Output Stream Classes Text Input and Output.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Guide To UNIX Using Linux Third Edition
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
Chapter 3 Interactivity and Expressions CSC 125 Introduction to C++ programming.
Binary Search Tree For a node: The left subtree contains nodes with keys less than the node's key. The right subtree contains nodes with keys greater than.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>,
Guide To UNIX Using Linux Fourth Edition
A Guide to Unix Using Linux Fourth Edition
1 Homework Introduction to HW7 –Complexity similar to HW6 –Don’t wait until last minute to start on it File Access will be needed in HW8.
Standard Input and Output. Overview Data communication with a C program and the outside world is performed through files Files are a non-volatile way.
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.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Lecture 8a: File I/O BJ Furman 21MAR2011. Learning Objectives Explain what is meant by a data stream Explain the concept of a ‘file’ Open and close files.
Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.
Chapter 11 File Processing. Objectives In this chapter, you will learn: –To be able to create, read, write and update files. –To become familiar with.
Lecture 11: Files & Arrays B Burlingame 18 November 2015.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
Python – May 12 Recap lab Chapter 2 –operators –Strings –Lists –Control structures.
Learners Support Publications Working with Files.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
IO revisited CSE 2451 Rong Shi. stdio.h Functions – printf – scanf(normally stops at whitespace) – fgets – sscanf Standard streams – stdin(defaults to.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Files in Python Opening and Closing. Big Picture To use a file in a programming language – You have to open the file – Then you process the data in the.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني I/O and File management Concept of streams. cin and cout objects. C++stream classes. Unformatted I/O.
CIRC Summer School 2016 Baowei Liu
Chapter 1 Connections to Algebra Review
Input from STDIN STDIN, standard input, comes from the keyboard.
Shell Features CSCI N321 – System and Network Administration
CIRC Summer School 2017 Baowei Liu
Chapter 7 Text Input/Output Objectives
Topics discussed in this section:
Chapter 7 Text Input/Output Objectives
CIRC Winter Boot Camp 2017 Baowei Liu
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
INTRODUCTION Every language has some features that provides interaction between the program and the user of the program. C language uses the reference.
TMF1414 Introduction to Programming
Chapter 7 Text Input/Output Objectives
CS1010 Programming Methodology
8/30/2018 CPRG 215 Introduction to Object-Oriented Programming with Java Module 5- The java.io Package Topic 5.1 Input and Output Streams, Readers.
Intro to Ethical Hacking
CSI 121 Structured Programming Language Lecture 7: Input/Output
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Intro to Ethical Hacking
Chapter Four UNIX File Processing.
Evaluating Logarithms
Weeks 9-10 IO System Calls Standard IO (stdin, stdout) and Pipes
Exponential and Logarithmic Forms
FILE handeling.
Chapter 6.
EECE.2160 ECE Application Programming
CSc 352 File I/O Saumya Debray Dept. of Computer Science
Topics discussed in this section:
Presented by, Mr. Satish Pise
Challenge Guide Grade Code Type Slides
Presentation transcript:

Internship in DASAN networks C programing language Chapter 7 : Input and Output Present by Le Thi Hien 1/14

Contents  Standard Input and Output  Variable-length Argument List  Formatted Output  Formatted Input  File Access  Error Handling  Line Input and Output 2/14

Standard Output and Input  Standard input (stdin) : data going into a programe. typical from keyboard.  Standard output (stdout): the stream where a program writes its output data. 3/14

Standard Input and Output Standard input/ output can be substituted by  File : Input :Prog <infile Output :Prog >outfile Example : ./a.out >result.c ./a.out <result.c  Pipeline : Otherprog | prog Prog | anotherprog 4/14

Variable-length Argument Lists  Syntax : type name (arg1,…);  Example : void minprintf(char *fmt,…) { va_list ap; va_start(ap, fmt);/*ap point to 1 st unnamed arg*/ … case ‘d’ : ival = va_arg(ap, int); … va_end(ap); } -Need #include - va_list type - Macro : va_start(va_list ap, lastfix); va_arg(va_list ap, type); va_end(va_list ap); 5/14

Fomatted Output SyntaxUseReturn valueExample int printf(const char *format,…); Write data to stdout as the format argument specifies -Success : total number of characters written -Fail : negative number printf(“%d\n”, a); int fprintf(FILE* stream, const char* format,…); Write data to the specified stream as the format argument specifies fprintf(stdout, “%s\n”,c); int sprintf(char (str, const char *format,…); Write data to stringsprintf(s, “%s if %d”, a, b); 6/14

Formatted Input SyntaxUseReturn valueExample Int scanf(const char* format, …); Read data from stdin and store according to the format into the location pointed by additional argument - Success : the number of items successfully read - Fail : EOF Scanf(“%d”, &a) Int fscanf(FILE* stream, const char*format,…); Read formatted data from stream FILE *fp = fopen(…); int f; Fscanf(pf,”%d”, &f); Int sscanf(const char* str, const char* format, …) Read formatted data from string Char *s; Sscanf(s, “%d”, &f) 7/14

Formats 8/14

Formats 9/14

File Access  FILE *fopen (const char* name, char *mode);  int fclose(FILE* fp);  Example : Ex1 : FILE* fp; fp = fopen(“mytext.txt”, “r”); Ex2 : stdin stdout stderr -Type FILE * -Constant. 10/14

File Access SyntaxUseReturn valueExample int getc(FILE* fp);Get a character from stream defined by fp -Success : intvalue of character. -EOF : EOF. -Fail : error indicator is set int a; fp = fopen(“text.txt”, “r”); a = getc(fp); int getchar(void);  #define getchar() getc(stdin) Get a character from stdin char c; c = getchar(); char* fgets(char* str, int num, FILE* pf); Get maximum (num - 1) character from stream defined by fp -Success : str -EOF or error : NULL char *s; fgets(s, 5, fp); 11/14

File Access SyntaxUseReturn valueExample Int putc (int c, FILE * fp);Write character to stream defined by fp Success : the character is written Fail : EOF and error indicator is set Int a; FILE *pf = fopen(“text.txt”, “w”) Putc(a, pf); Int putchar(int c);  int putc(c, stdout); Write character to stdoutInt b; B = putchar(a); Int *fputs(const char* str, FILE *pf); Write string pointed by str to stream defined by pf until reach ‘\0’. Success : non-negative Error : EOF Char *s; Fputs(s, pf); 12/14

stderr  Why need stderr ?  int ferror(FILE *fp); /*check error indicator. If error indicator is set, return non-zero value. Otherwise, return 0.*/  int feof(FILE *fp); /*check EOF indicator. If EOF indicator is set, return non- zero value. If not, return 0.*/ 13/14

Thank you ! 14