1 Input/Output and Debugging  How to use IO Streams  How to debug programs.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

PHP Form and File Handling
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.
1 Input/Output and Debugging  How to use IO Streams  How to debug programs  Help on coursework.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
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.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
UNIT 12 UNIX I/O Redirection.
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.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
C++ plus. 2 Goals Some general C++ tips 3 C++ Tips is header file for a library that defines three stream objects Keyboard an istream object named cin.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
The graphing calculator can be a great checking tool or a fast way to answer a multiple choice question. Example – suppose you graphed the following and.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
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.
Computer Programming for Engineers Introduction to Programming in C Language on Visual C Platform Intro. Comp. Prog. C-Language1.
File Handling Spring 2013Programming and Data Structure1.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
My Second FPGA for Altera DE2-115 Board 數位電路實驗 TA: 吳柏辰 Author: Trumen.
File Input and Output in C++. Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Storing and Retrieving Data
5 1 Data Files CGI/Perl Programming By Diane Zak.
Outline Overview Opening a file How to create a file ? Closing a File Check End-of-file Reading a File Line by Line Reading a File Character by Character.
Module 1.5 Problems with I/O devices and storage Theme: Finding solutions.
Using Oracle-Supplied Packages. 2 home back first prev next last What Will I Learn? Describe two common uses for the DBMS_OUTPUT server-supplied package.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
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.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Hints on debugging
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:
Programming Errors. Errors of different types Syntax errors – easiest to fix, found by compiler or interpreter Semantic errors – logic errors, found by.
File Handling in QBASIC
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Potential NEALP candidates Where is the data input site?
IT Chapter 2 Part A How Computers Work Input, process, output, and storage The operating system helps the computer perform four basic operations,
Chapter 14: Sequential Access Files
Great way to learn is by example so fire up Visual Studios C (at home make sure you custom install with C++ - no longer default) by Deborah R. Fowler.
My Second FPGA for Altera DE2-115 Board
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Introduction to Programming
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.
Chapter 7 Text Input/Output Objectives
Testing and Debugging.
CS1010 Programming Methodology
Computer Programming I
Copyright © 2003 Pearson Education, Inc.
CS111 Computer Programming
The Little Crab Scenario
CSE341: Programming Languages Section 1
Teaching London Computing
MicroEconomix 1500 RSLogix 500 LAB#1
IO Overview CSCE 121 J. Michael Moore
CS150 Introduction to Computer Science 1
Manual Water Ski Directory
AC Dipole Control part of Multiturn application
Chapter 3 Debugging Section 3.4
Chapter 1 c++ structure C++ Input / Output
IO Overview CSCE 121 Strongly influenced by slides created by Bjarne Stroustrup and Jennifer Welch.
CSc 352 File I/O Saumya Debray Dept. of Computer Science
Presentation transcript:

1 Input/Output and Debugging  How to use IO Streams  How to debug programs

2 IO Streams In default, both input stream is computer keyboard and output stream is screen. When we want to input from or output to files, we need to open IO streams, and close them at the end. These invoke the UNIX function fopen and fclose.

3 Built-ins for open/close IO Streams open(FileName, Mode, Stream) Close(Stream) FileName is an atom. Mode is one of: read - open the file for input. write - open the file for output. The file is created if it does not already exist, the file will otherwise be truncated. append - open the file for output. The file is created if it does not already exist, the file will otherwise be appended to.

4 Built-ins for open/close IO Streams An example: mk_html_file:- open(‘tmp.html’, write, S), write(S, ' '), nl(S), write(S, ' tmp '), nl(S), write(S, ' '), nl(S), write(S, ' a tmp file '), nl(S), write(S, ' '), 4close(S).

5 Just Add Stream Name! - Standard IO - write(Term) read(term) nl tab(N) - Files IO - write(Stream, Term) read(Stream, term) nl(Stream) tab(Stream, N)

6 Debugging How to fix syntax errors Read error messages carefully Common problems: missing brackets, semi-colons, full stops. Watch out ‘here’

7 Examples of Error Messages program([H|T):- do_something(H), program(T) ! Syntax error ! ] or operator expected ! in line 2 ! program ( [ H | T ! > ! ) :- do_something ( H ), program ( T ). ! Syntax error ! operator expected after expression ! in line 16 ! program ( [ H | T ] ) :- do_something ( H ), program ( T ) ! >

8 Debugging You can use ?- listing(prog_name). to checking if loaded program is correct. Existence error in user:progr/1 means progr/1 is not defined In order to track down what is wrong, use ?- trace. To turn the debug mode on ( notrace to switch it off)

9 The Procedure Box Control Flow Model * * Call | | Exit ----> | d(X,Y) :- o(X,Y). | ----> | | | d(X,Z) :- | <---- | o(X,Y), d(Y,Z). | <---- Fail | | Redo * *

10 When the trace mode is on, we can see everything step by step The code is program([H|T]):- H=1, program(T) | ?- program([_,_,_]). no | ?- trace. % The debugger will first creep – showing everything (trace) yes ?- program([_,_,_]). 1 1 Call: program([_435,_451,_467]) ? 2 2 Call: _435=1 ? 2 2 Exit: 1=1 ? 3 2 Call: program([_451,_467]) ? 4 3 Call: _451=1 ? 4 3 Exit: 1=1 ? 5 3 Call: program([_467]) ? 6 4 Call: _467=1 ? 6 4 Exit: 1=1 ? 7 4 Call: program([]) ? 7 4 Fail: program([]) ?

11 Options when trace the program ?- program([_,_,_]). 11 Call: program([_435,_451,_467]) ? You can type the following options: RET - creeps - skip a - abortn - switch off debug g - view ancestors h - print out all options

12 If you don’t want to trace every step leash(+Mode) Leashing Mode determines the ports of invocation boxes at which you are to be prompted when you creep through your program Mode is a list which can the following options: [call,exit,redo,fail,exception]).

13 Example of using “leash” try:- do1(X), do2(Y), do3(1). do1(a). do2(b). do3(c). | ?- try. no |?- leash([fail]). % Using leashing stopping at [fail] ports yes | ?- trace. % The debugger will first creep -- showing everything (trace) | ?- try. 1 1 Call: try 2 2 Call: do1(_550) 2 2 Exit: do1(a) 3 2 Call: do2(_545) 3 2 Exit: do2(b) 4 2 Call: do3(1) 4 2 Fail: do3(1) ?

14 Hint for course work 1 cango/4 needs to extend to cango/6 cango(X,Y, Path, Line):- cango(X,Y, [X], Path, [], Line). Why should it like this? As part of documentation, you need to explain it in your code