The usually used output statement is printf (). It is one of the library functions.
Syntax : printf (“format string”, argument list);
Format string may be a collection of escape sequence or/and conversion specification or/and string constant. The format string directs the printf function to display the entire text enclosed within the double quotes without any change.
Escape sequence:
Escape sequence is a pair of character. The first letter is a slash followed by a character. Escape sequence help us to represent within the format string invisible and non-printed character although there are physically two characters in any escape sequence. It actually represents only one. The various escape sequences are
Escape sequence | Meaning | ||||
\n | New line | ||||
\t | Tab | ||||
\b | Back space | ||||
\a | Bell | ||||
\o | Null character | ||||
\? | To print question mark | ||||
\\ | To print slash | ||||
\' | To print single quote | ||||
\" | To print double quote |
Conversion specification:
Conversion specification is also a pair of character. it is preceded by % and followed by a quote which may be a character. The Conversion specification inscribes the printf() function that it could print some value at that location in the text. The Conversion characters supported by C are
Conversion character | Meaning | ||||
%d | Data item is displayed as a signed decimal integer. | ||||
%i | Data item is displayed as a single decimal integer. | ||||
%f | Data item is displayed as a floating-point value without an exponent. | ||||
%c | Data item is displayed as a single character. | ||||
%e | Data item is displayed as a floating-point value with an exponent. | ||||
%g | Data item is displayed as a floating-point value using either e-type or f-type conversion depending on value. | ||||
%o | Data item is displayed as an octal integer, without a leading zero. | ||||
%s | Data item is displayed as string. | ||||
%u | Data item is displayed as an unsigned decimal integer. | ||||
%x | Data item is displayed as a hexadecimal integer, without a leading 0x. |
The following program illustrates the use of puts function.
转义字符:
\0 :字符串结束标志;
\n :换行(ascⅱ码为10);
\t :横向跳格;
\b :退格;
\r :回车(ascⅱ码为13);
\f :走纸换页;
\\ :字符\(ascⅱ码为92);
\' :单引号;
'\"':双引号;
\ddd:用8进制表示字符;
\xhh:用16进制表示字符
如果输入空串的话,程序就会输出 thanks