lecture05-jan29 - 1/29/10 EE312 - Lecture 5 Announcements...

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

View Full Document Right Arrow Icon
1/29/10 1 EE312 - Lecture 5 Announcements • Assignment 2 out next week – Monday – Downloading a free IDE • for Windows – http://www.microsoft.com/express/Downloads/#2008-Visual-CPP – http://www.dreamspark.com • for Mac ???? – Xcode, MPW, Eclipse, CodeWarrior » http://www.macupdate.com/info.php/id/8342 • Topics for today will address: – Formatted input – Introduction to algorithm design – conditionals in decision making statements – Start program control statements (Ch. 5 & 6) The scanf Function scanf ( “ Format string ”, list-of-variables ); Treats the input as a continuous stream of characters Each variable in the list must be preceded by the symbol & scanf format strings are similar to printf format strings, but usually contain only conversion specifications: int i, j; float x, y; scanf("%d%d%f%f", &i, &j, &x, &y); For each conversion spec (L to R), find the next corresponding value in the input stream, and then assign it to the variable – The type of variable, conversion spec and the input value should all match When used with scanf, the e, f, and g conversion specs are identical: each causes scanf to read a floating-point number. A sign, exponent, and decimal point may or may not be present. – Use %le for reading a double. How scanf works scanf ( ) scans each character when searching for an input item to match a format code. – It ignores white-space characters (blanks, tabs, and new-line characters) until it finds a non white-space character It reads the item, until a character that can’t belong is found For example (assume the declarations on previous slide): scanf ("%d%d%f%f", &i, &j, &x, &y); the input values could be split over several lines: 1 -20 .3 -4.0e3 or put on a single line: 1 -20 .3 -4.0e3 The character found that is not part of the current item is put back and read again during the scanning of the next input item or the next call to scanf. – Watch out for the newline at the end of a scanf , it is still in the buffer The scanf Format String A scanf format string may contain ordinary characters in addition to conversion specifications. A non-white-space character in a format string must match the next input character or scanf terminates without reading further. (The non-matching character can be read by a later call of scanf.) For example, the code int month, day, year; scanf("%d/%d/%d", &month, &day, &year); will read 5/ 28/ 2002 but not 5 / 28 / 2002 A white-space character in a format string matches zero or more white-space characters in the input. The call scanf("%d /%d /%d", &month, &day, &year); will read 5 / 28 / 2002 and similar inputs, regardless of the amount of space before or after
Background image of page 1

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

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

This note was uploaded on 03/15/2010 for the course EE 16005 taught by Professor Krasner during the Spring '10 term at University of Texas at Austin.

Page1 / 5

lecture05-jan29 - 1/29/10 EE312 - Lecture 5 Announcements...

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

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