lecture05-formatted IO

basic format specicaons used in the format string for

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ? prinA("Item\tUnit\tPurchase\n\tPrice\tDate\n"); 4 What does it do?   What does this print? prinA("\"Hello!\""); 5 Conversion Specifica=on   Placeholder represen=ng a value filled in during prin=ng   Specifies how a value is converted from its internal (binary) form into characters (printed form) 6 prinA() func=on (cont.)   Basic format specifica=ons used in the format string for outpu8ng values with prinA ( ) :   %d decimal integer   %f floa=ng point decimal fixed format   %e exponen=al floa=ng point decimal   %c character   %s C string (character array, null terminated) 7 prinA ( ) func=on (cont.)     Ordinary characters are printed as they appear in the format string Conversion specifica=ons are matched one ­by ­one with the remaining arguments : int i = 10, j = 20; double x = 43.2892, y = 5527.0; prinA("i = %d, j = %d, x = %f, y = %f\n", i, j, x, y);   2. What is the output from this prinA statement? 8 prinA ( ) func=on (cont.)     Warning: C compilers don t check to see if the number of conversion specifica=ons in a format string matches the number of output items. Assume int i,j and double x 3. prinA("%d %d\n", i); /* too few values  ­ what happens? */ 4. prinA("%d\n", i, j); /* too many values, what happens?*/   Furthermore, there s no check that a conversion specifica=on is appropriate for the type of value being printed: 5. prinA("%f %d\n", i, x); /* what happens ? */ 9 printf() Conversion Specifications   A …printf conversion specification consists of the % character, followed by as many as five distinct items:   A conversion specification has the form %fm.pX   f(optional) indicat...
View Full Document

This note was uploaded on 10/06/2013 for the course EE 312 taught by Professor Shafer during the Fall '08 term at University of Texas.

Ask a homework question - tutors are online