EXAMINATION REGULATIONS and REFERENCE MATERIAL for ENCM 339 Fall 2017 Section 01 Final Examination

Size: px
Start display at page:

Download "EXAMINATION REGULATIONS and REFERENCE MATERIAL for ENCM 339 Fall 2017 Section 01 Final Examination"

Transcription

1 EXAMINATION REGULATIONS and REFERENCE MATERIAL for ENCM 339 Fall 2017 Section 01 Final Examination The following regulations are taken from the front cover of a University of Calgary examination answer booklet. They are all in effect for the ENCM 339 examination, except that you are to write your answers on the question paper, not in an answer booklet. STUDENT IDENTIFICATION Each candidate must sign the Seating List confirming presence at the examination. All candidates for final examinations are required to place their University of Calgary I.D. cards on their desks for the duration of the examination. (Students writing mid-term tests can also be asked to provide identity proof.) Students without an I.D. card who can produce an acceptable alternative I.D., e.g., one with a printed name and photograph, are allowed to write the examination. A student without acceptable I.D. will be required to complete an Identification Form. The form indicates that there is no guarantee that the examination paper will be graded if any discrepancies in identification are discovered after verification with the student s file. A Student who refuses to produce identification or who refuses to complete and sign the Identification Form is not permitted to write the examination. EXAMINATION RULES (1) Students late in arriving will not normally be admitted after one-half hour of the examination time has passed. (2) No candidate will be permitted to leave the examination room until one-half hour has elapsed after the opening of the examination, nor during the last 15 minutes of the examination. All candidates remaining during the last 15 minutes of the examination period must remain at their desks until their papers have been collected by an invigilator. (3) All inquiries and requests must be addressed to supervisors only. (4) Candidates are strictly cautioned against: (a) speaking to other candidates or communicating with them under any circumstances whatsoever; (b) bringing into the examination room any textbook, notebook or memoranda not authorized by the examiner; (c) making use of calculators and/or portable computing machines not authorized by the instructor; (d) leaving answer papers exposed to view; (e) attempting to read other student s examination papers. The penalty for violation of these rules is suspension or expulsion or such other penalty as may be determined. (5) Candidates are requested to write on both sides of the page, unless the examiner has asked that the left hand page be reserved for rough drafts or calculations. (6) Discarded matter is to be struck out and not removed by mutilation of the examination answer book. (7) Candidates are cautioned against writing in their answer book any matter extraneous to the actual answering of the question set. (8) The candidate is to write his/her name on each answer book as directed and is to number each book. (9) A candidate must report to a supervisor before leaving the examination room. (10) Answer books must be handed to the supervisor-in-charge promptly when the signal is given. Failure to comply with this regulation will be cause for rejection of an answer paper. (11) If during the course of an examination a student becomes ill or receives word of a domestic affliction, the student should report at once to the supervisor, hand in the unfinished paper and request that it be cancelled. If physical and/or emotional ill health is the cause, the student must report at once to a physical/counsellor so that subsequent application for a deferred examination is supported by a completed Physician/Counsellor Statement form. Students can consult professionals at University Health Services or University Counselling Services during normal working hours or consult their physician/counsellor in the community. Should a student write an examination, hand in the paper for marking, and later report extenuating circumstances to support a request for cancellation of the paper and for another examination, such a request will be denied. (12) Smoking during examinations is strictly prohibited. Reference material appears on the following pages...

2 ENCM 339 Fall 2017 Section 01: Reference Material for Final Examination page 2 of 6 Introduction Documentation for some C library facilities starts on this page and continues on page 3. Documentation and/or examples for some Python language features and library facilities can be found on pages 4 6. Documentation for some C library facilities int strcmp(const char *left, const char *right); Each argument must be a pointer to the beginning of a string. If the two strings match exactly, the return value is 0. If the string accessed via left is less than the string accessed via right, the return value is < 0. If the string accessed via left is greater than the string accessed via right, the return value is > 0. Examples, which assume that the character set in use is ASCII: strcmp("ab", "ab") would return 0. strcmp("ab", "ac") would return a value < 0. strcmp("aba", "ab") would return a value > 0. strcmp("ab", "Z") would return a value > 0, because uppercase letters have lesser ASCII code values than lowercase letters. void* malloc(size_t nbytes); size_t is a typedef for some unsigned integer type. nbytes must be greater than or equal to 1. malloc returns either a pointer to the beginning of a newly allocated block of nbytes bytes in the heap, or NULL to indicate that it could find no such block. The bytes in the allocated block are not initialized any particular value. void free(void *p); p must be either NULL or a pointer to the beginning of a block of bytes allocated using malloc. If p is NULL, free does nothing; otherwise free deallocates the block pointed to by p. FILE* fopen(const char *filename, const char *mode); filename and mode must point to the beginnings of strings. fopen tries to open the file named by filename in the mode specified by mode. Modes used in ENCM 339 include: "r" for reading from a text file and "rb" for reading from a binary file; "w" for writing to a text file, either creating a new file, or replacing the contents of an older file; "a" for writing to a text file, either creating a new file, or appending to the contents of an older file; "wb" and "ab", similar to "w" and "a", but for binary files. (There are many other possible modes.) If fopen succeeds it returns a pointer that can be used for further operations on the file; if fopen fails, it returns NULL. EOF EOF is a preprocessor macro defined as some negative integer constant. It is used by many (not all!) standard C library I/O functions as a return value to indicate an error, possibly end-of-file, and possibly some other kind of error. int fclose(file *stream); stream must be a file pointer corresponding to an open file. fclose breaks the connection between program and file. It returns EOF to indicate that errors were detected in closing the file, and 0 otherwise. int fgetc(file *stream); stream must be a file pointer corresponding to a text file open for input. fgetc normally reads the next character from stream and returns its character code. fgetc returns EOF to indicate end-of-file or error.

3 ENCM 339 Fall 2017 Section 01: Reference Material for Final Examination page 3 of 6 char* fgets(char *s, int size, FILE *stream); s must point to the beginning of an array that has at least size chars of storage, and stream must be a file pointer corresponding to a text file open for input. fgets will read characters from stream and copy them into the array until one of the following things has happened: a newline character has been read and copied into the array; size - 1 characters have been read and copied, with none of them being a newline; EOF was returned on an attempt to read a character in this case, EOF is not copied into the array. In each of the three cases, fgets will terminate the string in the array with a \0. The return value is s if at least one character was copied into the array, and NULL otherwise. int fscanf(file *stream, const char *format,...); stream must be a file pointer corresponding to a text file open for input. In this simple example... int i, j; i = fscanf(fp, "%d", &j);... i will get a value of 1 on success, 0 on failure because the wrong kinds of characters were in the input stream, and EOF on failure for some other reason. int fputc(int c, FILE *stream); stream must be a file pointer corresponding to a text file open for output. c must be a character code. fputc writes the character code to the output file. int fputs(const char *s, FILE *stream); stream must be a file pointer corresponding to a text file open for output. s must point to the beginning of a string. fputs writes all of the characters in the string, up to but not including the terminating \0, to the output file. int fprintf(file *stream, const char *format,...); stream must be a file pointer corresponding to a text file open for input. In this simple example... fprintf(fp, "hello %d", 100-1);... the character sequence hello 99 will be written to the output stream. size_t fread(void *p, size_t size, size_t count, FILE *stream); stream must be a file pointer corresponding to a binary file open for input. p must point to the beginning of a chunk of at least size*count bytes of memory. fread attempts to copy count items, each item size bytes in size, from the file to memory. The return value is the number of items actually copied from the file. size_t fwrite(const void *p, size_t size, size_t count, FILE *stream); stream must be a file pointer corresponding to a binary file open for output. p must point to the beginning of a chunk of at least size*count bytes of memory. fwrite attempts to copy count items, each item size bytes in size, from memory to the file. The return value is the number of items actually copied to the file. stdin, stdout and stderr stdin, stdout, and stderr can be thought of as constants of type FILE*. stdin is the standard input stream, accessed, for example, using scanf. stdout is the standard output stream, accessed, for example, using printf. stderr is another output stream, and is the preferred channel for error messages.

4 ENCM 339 Fall 2017 Section 01: Reference Material for Final Examination page 4 of 6 Python documentation and code examples A few important builtin functions len(container) number of items in a sequence, or number of key-value pairs in a dict object. print(arguments) print output. By default, print puts a space between each argument value and a newline at the end, but that can be changed with sep=string and/or end=string. Use file=fileobject to send output to a file instead of the terminal. input(string) get a line of text from interactive input, using string as a prompt. range(stop) integers from 0 up to but not including stop, with a step of 1. range(start, stop) integers from start up to but not including stop, with a step of 1. range(start, stop, step) integers from start up to but not including stop, with a step of step. isinstance(object, type) True if the type of object is either type or a class that inherits from type; otherwise, False. open(filename, mode) open a file. Modes presented in ENCM 339 in Fall 2017 were: r w a x open text file for input open text file for output, either creating a new file or replacing an existing one open text file for output, either creating a new file or adding text at the end of an existing one open text file for output, but only if the file does not already exist open raises an instance of an OSError exception if it fails to open the file. Examples of container creation a = [ ] b = [5, cde ] c = () d = 7, e = fgh, 2.25 f = { } g = {339: fun, 353: also fun } Growing and shrinking lists Examples copy/pasted from an interactive session: = [12, 35, 27, 19].append(34) [12, 35, 27, 19, 34].insert(2, 42) [12, 35, 42, 27, 19, 34] >>> del mylist[3] [12, 35, 42, 19, 34] >>> del mylist[1:4] [12, 34] Splitting and joining strings Examples copy/pasted from an interactive session: # empty list # list with two items # empty tuple # tuple with 1 item # tuple with 2 items # empty dict # dict with 2 int keys

5 ENCM 339 Fall 2017 Section 01: Reference Material for Final Examination page 5 of 6 >>> mystr = this that other = mystr.split() [ this, that, other ] >>> mynewstr = /.join(mylist) >>> mynewstr this/that/other Examples of slices expression type value (23, 16, 31)[0:-1] tuple (23, 16) ABCDEFGHIJ [1:9:2] str BDFH [52, 55, 63, 68][-1:0:-1] list [68, 63, 55] Some operations with dictionaries key in dict True if key is in dict, False if key is not in dict. dict[key] = value update a key-value pair if key is already in dict; otherwise add a new key-value pair. del dict[key] remove key-value pair from dict. A KeyError exception is raised if key is not in dict. variable = dict[key] give variable the value associated with key. A KeyError exception is raised if key is not in dict. variable = dict.get(key) give variable the value associated with key, or None if key is not in dict. # Loop over keys. for k in dict: statement(s) # Loop over values. for v in dict.values(): statement(s) # Loop over key-value pairs. for k, v in dict.items(): statement(s) Text file input example: one line at a time somefile.txt line one line two line three line four line five program with open( somefile.txt ) as f: for line in f: print(line, end = "") if line == line three\n : break output line one line two line three Text file input example: all the lines at once Assume that somefile.txt is as given above. program with open( somefile.txt ) as f: lines = f.readlines() print(lines) output [ line one\n, line two\n, line three\n, line four\n, line five\n ] Text file output examples Both programs write 1, 2, 4, 8, 16, and 32 to powers.txt, one number per line. with open( powers.txt, w ) as f: for i in range(6): f.write(str(2**i) + \n ) with open( powers.txt, w ) as f: for i in range(6): print(2**i, file=f)

6 ENCM 339 Fall 2017 Section 01: Reference Material for Final Examination page 6 of 6 Example code with class types class SmartDog: def init (self, bark_par, age_par=0): self.bark, self.age = bark_par, age_par def str (self): f = {}-year-old dog who says {} return f.format(self.age, self.bark) def say_n(self, n): if n <= 0: print( [whimper] ) else: for i in range(n): print(self.bark, end=" ") print() def say_age(self): self.say_n(self.age) class PlusDog(SmartDog): def add(self, j, k): self.say_n(j + k) class TimesDog(SmartDog): def multiply(self, j, k): self.say_n(j * k) class SmartestDog(PlusDog, TimesDog): pass lassie = SmartestDog( ruff, 4) lassie.say_age() print(lassie) lassie.add(2, 3) lassie.multiply(2, 3) output of program ruff ruff ruff ruff 4-year-old dog who says ruff ruff ruff ruff ruff ruff ruff ruff ruff ruff ruff ruff Example code with exception handling secret = 7 while True: try: guess = int(input( Guess my integer? )) if guess == secret: break print( Sorry,, guess, is incorrect. ) except ValueError: print("that wasn t an integer!") print(guess, is correct! ) Below is an example dialog with the above program. User input is shown in a slanted font. Guess my integer? hello That wasn t an integer! Guess my integer? 6 Sorry, 6 is incorrect. Guess my integer? 7 7 is correct!

File IO and command line input CSE 2451

File 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 information

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

Content. 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 information

Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 8 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2017 ENCM 339 Fall 2017 Section 01 Slide

More information

System Software Experiment 1 Lecture 7

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 information

Input/Output and the Operating Systems

Input/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 information

Introduction to file management

Introduction 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 information

C-Refresher: Session 10 Disk IO

C-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 information

File I/O. Arash Rafiey. November 7, 2017

File 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 information

Mode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.

Mode 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 information

C mini reference. 5 Binary numbers 12

C 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 information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE 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 information

C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x;

C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x; C Input/Output Before we discuss I/O in C, let's review how C++ I/O works. int i; double x; cin >> i; cin >> x; cout

More information

Slide Set 15 (Complete)

Slide Set 15 (Complete) Slide Set 15 (Complete) for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary November 2017 ENCM 339 Fall 2017

More information

25.2 Opening and Closing a File

25.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 information

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre Programming in C Session 8 Seema Sirpal Delhi University Computer Centre File I/O & Command Line Arguments An important part of any program is the ability to communicate with the world external to it.

More information

C for Engineers and Scientists: An Interpretive Approach. Chapter 14: File Processing

C 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 information

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.

Quick 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 information

CMPE-013/L. File I/O. File Processing. Gabriel Hugh Elkaim Winter File Processing. Files and Streams. Outline.

CMPE-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 information

Standard C Library Functions

Standard 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 information

Chapter 5, Standard I/O. Not UNIX... C standard (library) Why? UNIX programmed in C stdio is very UNIX based

Chapter 5, Standard I/O. Not UNIX... C standard (library) Why? UNIX programmed in C stdio is very UNIX based Chapter 5, Standard I/O Not UNIX... C standard (library) Why? UNIX programmed in C stdio is very UNIX based #include FILE *f; Standard files (FILE *varname) variable: stdin File Number: STDIN_FILENO

More information

CS240: Programming in C

CS240: 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 information

HIGH LEVEL FILE PROCESSING

HIGH 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 information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 12

BIL 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 information

Standard File Pointers

Standard 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 information

ECE551 Midterm Version 1

ECE551 Midterm Version 1 Name: ECE551 Midterm Version 1 NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual

More information

Systems Programming. 08. Standard I/O Library. Alexander Holupirek

Systems 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 information

University of Calgary Department of Electrical and Computer Engineering ENCM 339 Lecture Section 01 Instructor: Steve Norman

University of Calgary Department of Electrical and Computer Engineering ENCM 339 Lecture Section 01 Instructor: Steve Norman page 1 of 6 University of Calgary Department of Electrical and Computer Engineering ENCM 339 Lecture Section 01 Instructor: Steve Norman Fall 2017 MIDTERM TEST Wednesday, November 1 7:00pm to 9:00pm This

More information

Standard I/O in C, Computer System and programming in C

Standard 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 information

CP2 Revision. theme: file access and unix programs

CP2 Revision. theme: file access and unix programs CP2 Revision theme: file access and unix programs file access in C basic access functionality: FILE *fopen(const char *filename, const char *mode); This function returns a pointer to a file stream (or

More information

I.D. NUMBER SURNAME OTHER NAMES

I.D. NUMBER SURNAME OTHER NAMES THE UNIVERSITY OF CALGARY DEPARTMENT OF COMPUTER SCIENCE DEPARTMENT OF MATHEMATICS AND STATISTICS FINAL EXAMINATION SOLUTION KEY CPSC/PMAT 418 L01 Introduction to Cryptography Fall 2017 December 19, 2017,

More information

C programming basics T3-1 -

C 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 information

Procedural Programming

Procedural Programming Exercise 5 (SS 2016) 28.06.2016 What will I learn in the 5. exercise Strings (and a little bit about pointer) String functions in strings.h Files Exercise(s) 1 Home exercise 4 (3 points) Write a program

More information

ECE551 Midterm Version 1

ECE551 Midterm Version 1 Name: ECE551 Midterm Version 1 NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual

More information

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

CS246 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 information

Memory Layout, File I/O. Bryce Boe 2013/06/27 CS24, Summer 2013 C

Memory Layout, File I/O. Bryce Boe 2013/06/27 CS24, Summer 2013 C Memory Layout, File I/O Bryce Boe 2013/06/27 CS24, Summer 2013 C Outline Review HW1 (+command line arguments) Memory Layout File I/O HW1 REVIEW HW1 Common Problems Taking input from stdin (via scanf) Performing

More information

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

CSC209H Lecture 3. Dan Zingaro. January 21, 2015 CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without

More information

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly.

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. Name: ECE551 Midterm NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual work. You

More information

University of Calgary Department of Electrical and Computer Engineering ENCM 335 Instructor: Steve Norman

University of Calgary Department of Electrical and Computer Engineering ENCM 335 Instructor: Steve Norman page 1 of 6 University of Calgary Department of Electrical and Computer Engineering ENCM 335 Instructor: Steve Norman Fall 2018 MIDTERM TEST Thursday, November 1 6:30pm to 8:30pm Please do not write your

More information

Lecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments

Lecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 7: Files opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 5: Files, I/O 0IGXYVI*MPIW 0 opening/closing files reading/writing

More information

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am) Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Reid Section: L0101 (10:10-11:00am) Do not turn this page until you have received the signal to start.

More information

ECE551 Midterm Version 2

ECE551 Midterm Version 2 Name: ECE551 Midterm Version 2 NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual

More information

SAE1A Programming in C. Unit : I - V

SAE1A Programming in C. Unit : I - V SAE1A Programming in C Unit : I - V Unit I - Overview Character set Identifier Keywords Data Types Variables Constants Operators SAE1A - Programming in C 2 Character set of C Character set is a set of

More information

MARKS: Q1 /20 /15 /15 /15 / 5 /30 TOTAL: /100

MARKS: 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 information

UNIT-V CONSOLE I/O. This section examines in detail the console I/O functions.

UNIT-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 information

This code has a bug that allows a hacker to take control of its execution and run evilfunc().

This code has a bug that allows a hacker to take control of its execution and run evilfunc(). Malicious Code Insertion Example This code has a bug that allows a hacker to take control of its execution and run evilfunc(). #include // obviously it is compiler dependent // but on my system

More information

Student Number: Instructor: Reid Section: L5101 (6:10-7:00pm)

Student Number: Instructor: Reid Section: L5101 (6:10-7:00pm) Final Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Reid Section: L5101 (6:10-7:00pm) Do not turn this page until you have received the signal to start.

More information

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty. ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.

More information

File (1A) Young Won Lim 11/25/16

File (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 information

Exercise Session 3 Systems Programming and Computer Architecture

Exercise Session 3 Systems Programming and Computer Architecture Systems Group Department of Computer Science ETH Zürich Exercise Session 3 Systems Programming and Computer Architecture Herbstsemester 2016 Agenda Review of Exercise 2 More on C-Programming Outlook to

More information

School of Computer Science & Software Engineering The University of Western Australia. Mid-Semester Test September 2017

School of Computer Science & Software Engineering The University of Western Australia. Mid-Semester Test September 2017 School of Computer Science & Software Engineering The University of Western Australia Mid-Semester Test September 2017 () This paper contains 1 section This paper contains: 8 pages (including this title

More information

Engineering program development 7. Edited by Péter Vass

Engineering program development 7. Edited by Péter Vass Engineering program development 7 Edited by Péter Vass Functions Function is a separate computational unit which has its own name (identifier). The objective of a function is solving a well-defined problem.

More information

2009 S2 COMP File Operations

2009 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 information

Fundamentals of Programming & Procedural Programming

Fundamentals of Programming & Procedural Programming Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Fundamentals of Programming & Procedural Programming Session Seven: Strings and Files Name: First Name: Tutor: Matriculation-Number: Group-Number:

More information

Input / Output Functions

Input / 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 information

Stream Model of I/O. Basic I/O in C

Stream Model of I/O. Basic I/O in C Stream Model of I/O 1 A stream provides a connection between the process that initializes it and an object, such as a file, which may be viewed as a sequence of data. In the simplest view, a stream object

More information

Programming & Data Structure

Programming & Data Structure File Handling Programming & Data Structure CS 11002 Partha Bhowmick http://cse.iitkgp.ac.in/ pb CSE Department IIT Kharagpur Spring 2012-2013 File File Handling File R&W argc & argv (1) A file is a named

More information

Student Number: Instructor: Reid Section: L0201 (12:10-1:00pm)

Student Number: Instructor: Reid Section: L0201 (12:10-1:00pm) Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Reid Section: L0201 (12:10-1:00pm) Do not turn this page until you have received the signal to start.

More information

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

CSci 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 information

M.CS201 Programming language

M.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 information

Files. Programs and data are stored on disk in structures called files Examples. a.out binary file lab1.c - text file term-paper.

Files. Programs and data are stored on disk in structures called files Examples. a.out binary file lab1.c - text file term-paper. File IO part 2 Files Programs and data are stored on disk in structures called files Examples a.out binary file lab1.c - text file term-paper.doc - binary file Overview File Pointer (FILE *) Standard:

More information

Organization of a file

Organization 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 information

CS 261 Fall Mike Lam, Professor. Structs and I/O

CS 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 information

Ch 11. C File Processing (review)

Ch 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 information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

File I/O. Last updated 10/30/18

File I/O. Last updated 10/30/18 Last updated 10/30/18 Input/Output Streams Information flow between entities is done with streams Keyboard Text input stream data stdin Data Text output stream Monitor stdout stderr printf formats data

More information

CSCI 171 Chapter Outlines

CSCI 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 information

University of Calgary Department of Electrical and Computer Engineering ENCM 339: Programming Fundamentals, Section 01 Instructor: Steve Norman

University of Calgary Department of Electrical and Computer Engineering ENCM 339: Programming Fundamentals, Section 01 Instructor: Steve Norman page 1 of 9 University of Calgary Department of Electrical and Computer Engineering ENCM 339: Programming Fundamentals, Section 01 Instructor: Steve Norman Fall 2017 FINAL EXAMINATION Location: ENG 60

More information

Lab # 4. Files & Queues in C

Lab # 4. Files & Queues in C Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4010: Lab # 4 Files & Queues in C Eng. Haneen El-Masry October, 2013 2 FILE * Files in C For C File I/O you need

More information

Files and Streams Opening and Closing a File Reading/Writing Text Reading/Writing Raw Data Random Access Files. C File Processing CS 2060

Files 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 information

File I/O. Preprocessor Macros

File 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 information

Laboratory: USING FILES I. THEORETICAL ASPECTS

Laboratory: USING FILES I. THEORETICAL ASPECTS Laboratory: USING FILES I. THEORETICAL ASPECTS 1. Introduction You are used to entering the data your program needs using the console but this is a time consuming task. Using the keyboard is difficult

More information

ECE 551D Spring 2018 Midterm Exam

ECE 551D Spring 2018 Midterm Exam Name: ECE 551D Spring 2018 Midterm Exam NetID: There are 6 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual

More information

CSE2301. Introduction. Streams and Files. File Access Random Numbers Testing and Debugging. In this part, we introduce

CSE2301. 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 information

C File Processing: One-Page Summary

C 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 information

Chapter 12. Files (reference: Deitel s chap 11) chap8

Chapter 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 information

Chapter 11 File Processing

Chapter 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 information

File I/O, Project 1: List ADT. Bryce Boe 2013/07/02 CS24, Summer 2013 C

File I/O, Project 1: List ADT. Bryce Boe 2013/07/02 CS24, Summer 2013 C File I/O, Project 1: List ADT Bryce Boe 2013/07/02 CS24, Summer 2013 C Outline Memory Layout Review Pointers and Arrays Example File I/O Project 1 List ADT MEMORY LAYOUT REVIEW Simplified process s address

More information

File Access. FILE * fopen(const char *name, const char * mode);

File Access. FILE * fopen(const char *name, const char * mode); File Access, K&R 7.5 Dealing with named files is surprisingly similar to dealing with stdin and stdout. Start by declaring a "file pointer": FILE *fp; /* See Appendix B1.1, pg. 242 */ header

More information

Do not turn this page until you have received the signal to start.

Do not turn this page until you have received the signal to start. CSCA08 Fall 2014 Final Exam Duration 160 minutes Aids allowed: none Student Number: A Instructor: Brian Harrington Last Name: First Name: UtorID (Markus Login): Do not turn this page until you have received

More information

Lecture 8. Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Lecture 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 information

Text Output and Input; Redirection

Text Output and Input; Redirection Text Output and Input; Redirection see K&R, chapter 7 Simple Output puts(), putc(), printf() 1 Simple Output The simplest form of output is ASCII text. ASCII occurs as single characters, and as nullterminated

More information

CS240: Programming in C

CS240: 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 information

ENG120. Misc. Topics

ENG120. 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 information

UNIT IV-2. The I/O library functions can be classified into two broad categories:

UNIT 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 information

Accessing 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 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 information

structs as arguments

structs as arguments Structs A collection of related data items struct record { char name[maxname]; int count; ; /* The semicolon is important! It terminates the declaration. */ struct record rec1; /*allocates space for the

More information

EECS2031. Modifiers. Data Types. Lecture 2 Data types. signed (unsigned) int long int long long int int may be omitted sizeof()

EECS2031. Modifiers. Data Types. Lecture 2 Data types. signed (unsigned) int long int long long int int may be omitted sizeof() 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 information

Day14 A. Young W. Lim Tue. Young W. Lim Day14 A Tue 1 / 15

Day14 A. Young W. Lim Tue. Young W. Lim Day14 A Tue 1 / 15 Day14 A Young W. Lim 2017-12-26 Tue Young W. Lim Day14 A 2017-12-26 Tue 1 / 15 Outline 1 Based on 2 C Strings (1) Characters and Strings Unformatted IO Young W. Lim Day14 A 2017-12-26 Tue 2 / 15 Based

More information

File and Console I/O. CS449 Spring 2016

File and Console I/O. CS449 Spring 2016 File and Console I/O CS449 Spring 2016 What is a Unix(or Linux) File? File: a resource for storing information [sic] based on some kind of durable storage (Wikipedia) Wider sense: In Unix, everything is

More information

Computer Programming Unit v

Computer 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 information

File Handling. Reference:

File 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 information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6

Darshan 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 information

Goals of this Lecture

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 system-level

More information

C for C++ Programmers

C for C++ Programmers C for C++ Programmers CS230/330 - Operating Systems (Winter 2001). The good news is that C syntax is almost identical to that of C++. However, there are many things you're used to that aren't available

More information

Goals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"

Goals of C  The Goals of C (cont.)  Goals of this Lecture The Design of C: A Rational Reconstruction Goals of this Lecture The Design of C: A Rational Reconstruction Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C Why? Learning

More information

File 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 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 information

Fundamentals of Programming. Lecture 10 Hamed Rasifard

Fundamentals 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 information

I/O Management! Goals of this Lecture!

I/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 information

I/O Management! Goals of this Lecture!

I/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 information

Course organization. Course introduction ( Week 1)

Course organization. Course introduction ( Week 1) Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and

More information