Engr 0012 (04-1) LecNotes 23-01. Engr 0012 (04-1) LecNotes 23-02 C++ errors/debugging build/compile compiler does not recognize a statement build/compile.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

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.
Week 5 Part I Kyle Dewey. Overview Exam will be back Thursday New office hour More on functions File I/O Project #2.
C Language.
I/O means Input and Output. One way: use standard input and standard output. To read in data, use scanf() (or a few other functions) To write out data,
ARDUINO CLUB Session 1: C & An Introduction to Linux.
UNIT 15 File Processing.
Week 4 – Functions Introduction. Functions: Purpose Breaking a large problem into a series of smaller problems is a common problem- solving technique.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
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.
Engr 0012 (04-1) LecNotes Engr 0012 (04-1) LecNotes arrays collection of values - all of the same type, e.g., int individual values referred.
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.
1 ICS103 Programming in C Lecture 8: Data Files. 2 Outline Why data files? Declaring FILE pointer variables Opening data files for input/output Scanning.
Topic 13 – Various Other Topics. Enumerated Types.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Programming in C #2 Input / Output.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
V-1 University of Washington Computer Programming I File Input/Output © 2000 UW CSE.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students C File Input and Output Checking input for errors.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
C Basic File Input/Output Manipulation C Programming – File Outline v File handling in C - opening and closing. v Reading from and writing to files.
Files Working with Files in C ATS 315. Files Misunderstandings about “files” In Windows and on Macs, we tend to think of files as “containing something”.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
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.
CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers.
EXERCISE Arrays, structs and file processing. Question An online store sells various types of children’s clothing. You are to create a program that stores.
Chapter 3 Input and Output
EXERCISE Arrays, structs and file processing. Question You own a pet store. You want to keep an inventory of all the pets that you have. Pets available.
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:
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
ME-2221 COMPUTER PROGRAMMING Lecture 18 FILE OPERATIONS Department of Mechanical Engineering A.H.M Fazle Elahi Khulna University of engineering & Technology.
Files A collection of related data treated as a unit. Two types Text
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
CSC Programming for Science Lecture 18: More Data Files.
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.
Connecting to Files In order to read or write to a file, we need to make a connection to it. There are several functions for doing this. fopen() – makes.
Engr 0012 (04-1) LecNotes Engr 0012 (04-1) LecNotes Contrasting MATLAB with C MATLABC language Workspace - interactive computation No real.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
University of Washington Computer Programming I
Chapter 7 Text Input/Output Objectives
File Access (7.5) CSE 2031 Fall July 2018.
File Input/Output.
Programming in C Input / Output.
Programming in C Input / Output.
Files I/O, Streams, I/O Redirection, Reading with fscanf
Engr 0012 (04-1) LecNotes
Engr 0012 (04-1) LecNotes
IPC144 Week 10 – Lesson 2 Working with Files
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
File Input and Output.
File Access (7.5) CSE 2031 Fall January 2019.
File Access (7.5) CSE 2031 Fall February 2019.
Programming in C Input / Output.
File Handling in C.
FILE handeling.
ETE 132 Lecture 8 By Munirul Haque.
ICS103: Programming in C 6: Pointers and Modular Programming
Files Chapter 8.
Presentation transcript:

Engr 0012 (04-1) LecNotes 23-01

Engr 0012 (04-1) LecNotes C++ errors/debugging build/compile compiler does not recognize a statement build/compile process stops error message(s) issued sometimes points to line with actual error sometimes points to line after error

Engr 0012 (04-1) LecNotes C++ errors/debugging run time build/compile has no errors program stops sometimes just stops

Engr 0012 (04-1) LecNotes C++ errors/debugging run time sometimes displays an error message like

Engr 0012 (04-1) LecNotes C++ errors/debugging run time sometimes displays an error message like

Engr 0012 (04-1) LecNotes C++ errors/debugging most common causes of run time errors division by zero using value rather than address in scanf using improper placeholder in scanf allowing array index to exceed amount in use

Engr 0012 (04-1) LecNotes file management creating a data file use your favorite text editor export (text) file from excel export a file from MATLAB use a data logger (experimental)

Engr 0012 (04-1) LecNotes file management opening a file requires a pointer to the file tells program where to find file declaring a FILE pointer // variable declaration FILE *pInfile; // input file pointer FILE *pOutfile; // output file pointer // variable declaration FILE *preadf; // input file pointer FILE *pwritef; // output file pointer file pointer type “value at” or pointer operator lower case “ p ” to remind you that this name is a pointer declaration normally in functions that use files

Engr 0012 (04-1) LecNotes file management opening a file for reading - basic pInfile = fopen("c:\temp\mydata.dat", "r" ); pointer name w/o * fopen function call file name/path read problems “hardwired” need to rewrite/recompile program to open a different file what happens if file not there? no error message!!! just keeps going

Engr 0012 (04-1) LecNotes file management opening a file for reading - better method pInfile = fReadOpen(); pointer name w/o * fReadOpen NOT in any.h library fReadOpen not in any text advantages asks user for file name checks for file existence fReadOpen available in Get12 fReadOpen function call

Engr 0012 (04-1) LecNotes file management opening a file for writing - basic pOutfile = fopen("c:\temp\myresults.out", "w" ); pointer name w/o * write problems “hardwired” need to rewrite/recompile program to open a different file what happens if file already there? no error message!!! just keeps going ==> destroys contents of file file name/path fopen function call

Engr 0012 (04-1) LecNotes file management opening a file for writing - better method pOutfile = fWriteOpen(); pointer name w/o * fWriteOpen NOT in any.h library fWriteOpen not in any text advantages asks user for file name checks for file existence fWriteOpen available in Get12 fWriteOpen function call

Engr 0012 (04-1) LecNotes file management reading from a file numread = fscanf( pInfile, "%lf", &value ); file pointer just created with fReadOpen “file” scanf placeholder for data type address to store value prototype for fscanf (and scanf ) is int fscanf( char[], … ); int scanf( char[], … ); fscanf (and scanf ) can return the number of values actually read in!!! we will exploit this to read files with an unknown number of entries

Engr 0012 (04-1) LecNotes file management writing to a file fprintf( pOutfile, "%7.2lf", value ); “file” fprintf file pointer just created with fReadOpen formatted placeholder for data type value to print only difference between fprintf and printf is the file pointer

Engr 0012 (04-1) LecNotes file management hygiene open a file??? close it when finished!!! fclose( pInfile ); or fclose( pOutfile );