石新柱的新家

导航

linux C print

4.1.1.The printf Function

  1. printf displays information on screen.
  2. printf returns the number of characters printed.
  3. printf displays the text you put inside the double quotes.
  4. printf requires the backslash character - an escape sequence - to display some special characters.
  5. printf can display variables by using the % conversion character.
  6. printf format: a string argument followed by any additional arguments.

4.1.2.The printf() Conversion Characters and flags

 
Conversion Character Displays Argument (Variable's Contents) As
%c Single character
%d Signed decimal integer (int)
%e Signed floating-point value in E notation
%f Signed floating-point value (float)
%g Signed value in %e or %f format, whichever is shorter
%i Signed decimal integer (int)
%o Unsigned octal (base 8) integer (int)
%s String of text
%u Unsigned decimal integer (int)
%x

Unsigned hexadecimal (base 16) integer (int)

4.1.3.Placeholders

The general form of a placeholder is: % flags field-width precision prefix type-identifier.

4.1.5.printf() Escape Sequences

 
Sequence Meaning
\a Beeps the speaker
\b Backspace (moves the cursor back, no erase)
\f Form feed (ejects printer page; may clear the screen on some computers)
\n Newline, like pressing the Enter key
\r Carriage return (moves the cursor to the beginning of the line)
\t Tab
\v Vertical tab (moves the cursor down a line)
\\ The backslash character
\' The apostrophe
\" The double-quote character
\? The question mark
\0 The "null" byte (that's 0, not the letter O)
\Onn A character value in octal (base 8)
\xnnn A character value in hexadecimal (base 16)

 

4.2.1.c: convert value to unsigned char and display

 

#include <stdio.h>
main()
{
    int i = 100;
    printf(" %c\n",i);
}

 

posted on 2012-02-10 10:57  shixinzhu  阅读(755)  评论(0编辑  收藏  举报