lecture_13

lecture_13 - Lecture 13 Comp 116 Feb 16th, 2009 Objectives...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style 10/6/09 Lecture 13 Comp 116 Feb 16th, 2009
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10/6/09 Objectives I/O screen files low level file I/O
Background image of page 2
10/6/09 Screen I/O (text)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10/6/09 I/O I/O – input / output
Background image of page 4
10/6/09 Revisiting ?printf sprintf: Formatted display of numbers/data fprintf: Similar function, directly prints to screen fprintf(‘Hello class!\n’) prints strings to the command window like disp(‘Hello Class!’)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10/6/09 fprintf fprintf( ‘ %d + %d = %d \n ’, 1, 2, (1 + 2)); The % character means you want a variable to be placed there in the string %d is for integers %f is for fixed point decimal (1.2345) %s is for a character string %c is for a single character fprintf(‘String’, variable1, variable2, …) You need a variable for each %
Background image of page 6
10/6/09 fprintf: escape sequences fprintf( ‘ %d + %d = %d \n ’, 1, 2, (1 + 2)); \ is used to indicate a special character \n ends the line \t adds a tab %% adds the % character How to use \ itself? \\ adds the \ character
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10/6/09 fprintf: output width fprintf( ‘pi to 2 digits: % .2 f \n ’, pi); fprintf( ‘pi to 4 digits: % 10.4 f \n ’, pi); % #.# formats the number The second # says how many digits after the decimal point to display The first # gives that much total room
Background image of page 8
10/6/09 fprintf Some examples Some really nice things about having to learn about % \ and # Using fprintf you can create (write to) files
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/22/2009 for the course COMP 116 taught by Professor Stotts during the Spring '08 term at UNC.

Page1 / 30

lecture_13 - Lecture 13 Comp 116 Feb 16th, 2009 Objectives...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online