1 / 14

Ch-9: Formatted Input Output

Ch-9: Formatted Input Output. Printing integers right-justified (Fig9.8). printf ( &quot;%4d<br>&quot;, 1 ); printf ( &quot;%4d<br>&quot;, 12 ); printf ( &quot;%4d<br>&quot;, 123 ); printf ( &quot;%4d<br>&quot;, 1234 ); printf ( &quot;%4d<br><br>&quot;, 12345 ); /* data too large */ printf ( &quot;%4d<br>&quot;, -1 ); printf ( &quot;%4d<br>&quot;, -12 );

ghalib
Télécharger la présentation

Ch-9: Formatted Input Output

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ch-9: Formatted Input Output

  2. Printing integers right-justified (Fig9.8) printf( "%4d\n", 1 ); printf( "%4d\n", 12 ); printf( "%4d\n", 123 ); printf( "%4d\n", 1234 ); printf( "%4d\n\n", 12345 ); /* data too large */ printf( "%4d\n", -1 ); printf( "%4d\n", -12 ); printf( "%4d\n", -123 ); printf( "%4d\n", -1234 ); /* data too large */ printf( "%4d\n", -12345 ); /* data too large */

  3. Right justifying and Left justifying in printf() (Fig9.11) printf( "%10s%10d%10c%10f\n\n", "hello", 7, 'a', 1.23 ); printf( "%-10s%-10d%-10c%-10f\n", "hello", 7, 'a', 1.23 );

  4. Printing numbers with and without the + flag in printf() (Fig9.12) printf( "%d\n%d\n", 786, -786 ); printf( "%+d\n%+d\n", 786, -786 );

  5. Printing a space before signed values not preceded by + or – (Fig9.13) printf( "%d\n% d\n", 547, -547 ); NOTE THE SPACE BETWEEN % and d

  6. Printing with the 0( zero ) flag fills in leading zeros (Fig9.15) printf( "%+09d\n", 452 ); printf( "%09d\n", 452 );

  7. Reading a string with scanf() (Fig9.20) char y; char x[6]; Scnaf(“%c%s”, &y, x); NOTE ABSENCE OF & x[0] x[1] x[2] x[3] x[4] x[5]

  8. Strings (of characters) Setting up string variables charLastName[10]; char city[12] = “Wilmington”; // Note “ charsubdivision[ ] = “Pine Valley”; // Note [ ] char State[10];

  9. Internal representation of strings charlastname[8] = “Adhar”; lastname[0]] lastname[1] lastname[2] lastname[3] lastname[4] lastname[5] lastname[6] lastname[7] A d h a r \0

  10. Reading a string with scanf() scanf (“%s”, LastName); // Note absence of & scanf (“%s”, State);

  11. Printing a string with printf() printf(“%s”, LastName); printf(“%s”, State);

  12. Using a scan set (Fig9.21) char z[ 9 ]; scanf( "%[aeiou]", z ); /* search for set of characters */

  13. Using an invertedscan set (Fig9.22) char z[ 9 ]; scanf( "%[^aeiou]", z ); /* avoid from the set of characters */

  14. Reading and discarding characters from the input stream (Fig 9.24) printf( "Enter a date in the form mm-dd-yyyy: " ); scanf( "%d%*c%d%*c%d", &month1, &day1, &year1 );

More Related