New version page

IUPUI CSCI 23000 - Basic I/O

Upgrade to remove ads

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View Full Document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Upgrade to remove ads
Unformatted text preview:

Slide 1Formatted Input/OutputFormatting Output with printfFormatting Output with printf (cont.)Slide 5Slide 6Slide 7Printing Floating-Point NumbersPrinting Strings and CharactersOther Conversion SpecifiersSlide 11Printing with Field Widths and PrecisionsPrinting with Field Widths and Precisions (cont)Slide 14Using Flags in the printf Format-Control StringSlide 16Slide 17Slide 18Printing Literals and Escape SequencesFormatting Input with ScanfSlide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Other Input / OutputFile AccessDale RobertsBasic I/O (Chap. 9)Basic I/O (Chap. 9)CSCI 230Department of Computer and Information Science,School of Science, IUPUIDale Roberts, Dale Roberts, LecturerLecturerDepartment of Computer and Information ScienceDepartment of Computer and Information ScienceIUPUIIUPUIDale RobertsFormatted Input/OutputFormatted Input/OutputIn this chapterIn this chapterPresentation of resultsPresentation of results scanfscanf and and printfprintfStreams (input and output)Streams (input and output)getsgets, , putsputs, , getchargetchar, , putcharputchar (in (in <stdio.h><stdio.h>))StreamsStreamsSequences of characters organized into linesSequences of characters organized into linesEach line consists of zero or more characters and ends with Each line consists of zero or more characters and ends with newline characternewline characterANSI C must support lines of at least 254 charactersANSI C must support lines of at least 254 charactersPerforms all input and outputPerforms all input and outputCan often be redirectedCan often be redirectedStandard input Standard input –– keyboard keyboardStandard output Standard output –– screen screenStandard error Standard error –– screen screenDale RobertsFormatting Output with Formatting Output with printfprintfprintfprintfPrecise output formattingPrecise output formattingConversion specifications: flags, field Conversion specifications: flags, field widths, precisions, etc.widths, precisions, etc.Can perform rounding, aligning columns, Can perform rounding, aligning columns, right/left justification, inserting literal right/left justification, inserting literal characters, exponential format, hexadecimal characters, exponential format, hexadecimal format, and fixed width and precisionformat, and fixed width and precisionDale RobertsFormatting Output with Formatting Output with printf printf (cont.)(cont.)FormatFormatprintf( format-control-string, other-arguments);Format control string: describes output format, Format control string: describes output format, Ordinary characters: copy to output stream: Ordinary characters: copy to output stream: printf(“this is printf(“this is an output\n”);an output\n”);Conversion specifications: leading with character ‘%’Conversion specifications: leading with character ‘%’Format:Format:%-w.plx%-w.plx[-]:[-]: optional optional  left justification, if exists left justification, if exists[w]:[w]: optional optional  minimal width (wider if necessary). The minimal width (wider if necessary). The padding character is padding character is blank normally and zero if the field blank normally and zero if the field width was specified with a leading zerowidth was specified with a leading zero[.]:[.]: optional optional  separates field w and p separates field w and pDale RobertsFormatting Output with Formatting Output with printf printf (cont.)(cont.)[p]:[p]: optional optional  maximum field width for a string maximum field width for a string  precision precision of floating numberof floating number[l]:[l]: long integer long integer[x]:d[x]:d  decimal signed integer decimal signed integer ii  decimal signed integer (the decimal signed integer (the dd and and ii specifiers are specifiers are different when used different when used in in scanfscanf)) uu  decimal unsigned integer decimal unsigned integer xx  hexadecimal unsigned integer ( hexadecimal unsigned integer (0 – 9 0 – 9 and and a – fa – f)) XX  unsigned hexadecimal integer ( unsigned hexadecimal integer (0 – 9 0 – 9 and and A – FA – F)) hh or or ll  length modifiers;length modifiers; place before any integer place before any integer conversion specifier to conversion specifier to indicate that a indicate that a shortshort or or longlong integer is displayed respectively integer is displayed respectivelyDale Robertshh or or ll  length modifiers;length modifiers; place before any integer place before any integer conversion specifier to conversion specifier to indicate that a indicate that a shortshort or or longlong integer is displayed respectively integer is displayed respectivelyoo  octal unsigned integer octal unsigned integerff  floating pointer number floating pointer numbergg  either either ff or or ee, whichever is shorter, whichever is shortercc  single character single characterss  character string character string ee  exponential floating pointer number exponential floating pointer numberOther-arguments: correspond to each conversion specification in Other-arguments: correspond to each conversion specification in format-control-string, such as variables.format-control-string, such as variables.Dale Roberts1 /* Fig 9.2: fig09_02.c */2 /* Using the integer conversion specifiers */3 #include <stdio.h>45 main()6 { 7 printf( "%d\n", 455 );8 printf( "%i\n", 455 ); /* i same as d in printf */9 printf( "%d\n", +455 );10 printf( "%d\n", -455 );11 printf( "%hd\n", 32000 );12 printf( "%ld\n", 2000000000 );13 printf( "%o\n", 455 );14 printf( "%u\n", 455 );15 printf( "%u\n", -455 );16 printf( "%x\n", 455 );17 printf( "%X\n", 455 );18 1920 }455455455-45532000200000000070745565081 1c71C7Example:Printing IntegersPrinting Integers–Whole number (no decimal point): 25, 0, -9–Positive, negative, or zero–Only minus sign prints by defaultProgram OutputDale RobertsPrinting Floating-Point NumbersPrinting Floating-Point NumbersFloating Point NumberFloating Point NumberHave a decimal point (Have a decimal point (33.533.5))Exponential notation Exponential notation (computer's version of (computer's version of scientific notation)scientific notation)150.3150.3 is is 1.503 x 10²1.503 x 10² in scientificin scientific150.3150.3 is is 1.503E+021.503E+02 in in exponential (exponential (%E%E stands for stands for exponent)exponent)Can


View Full Document
Download Basic I/O
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Basic I/O and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Basic I/O 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?