Printf C: description, formatting, examples

The standard console output function in C is printf. Its description is contained in the stdio.h header file. Using this function, you can display data or user messages to the console. C is case sensitive. For example, the two functions printf and scanf are different from the likes of Printf and Scanf. All characters in the printf and scanf functions must also be lowercase. One of the simplest examples of C printf to display the familiar hello world greeting is:

printf c description




Defining the functions of the printf group in the file "stdio.h"

The file "stdio.h" refers to the standard input / output library in C. The description of printf and similar functions is given in it as follows:

printf c description




, , .





printf

printf C . printf vprintf stdout, fprintf vfprintf , snprintf, sprintf, vsnprintf vsprintf . , .

printf c formatting




fprintf stream. , , sprintf. , .

snprintf , , . , bufsz ( ) . , bufsz , , , ( , ) .





printf_s , printf, . printf_s C printf : printf_s printf, .

printf.

C printf. printf C , stdout. , , , . - , , , , .

printf C , .

printf, int, , . , :

int k = printf(" %c %d %s", 'a', 11, "!"),

k , . ( "-1") , .

printf, "stdio.h" :

#include <stdio.h>

:

int printf(const char *, ...)

, . printf , , . , , , , , .

:

%[][][.][]

printf c variable output




printf C

, , : , , , , . , , . , , .

"%" , . , .

printf C . , , . , , , .

, , "%m$" "%" "*m$" "*", m, , ( ).

stream
buffer
bufsz, : - bufsz-1,
format, ,
,
-
+, , "+" ( "-" )
0, , . , . . "0" , "-"
space, , , . "space" , "+"
#
\a
\n
\r
\t
\v
\"
\\

printf C
%"%"
c. unsigned char. "l"unsigned char
s. charchar *
d

i
int
ounsigned int
x

X
. "a", "b", "c", "d", "e", "f" "x". "X" - "A", "B", "C", "D", "E", "F"unsigned int
u. 0,unsigned int
f

F
,double
e

E
, , , ( 6, 0, ). ""double
a

A
double
g

G
double
n, printf. , . ,int *
pvoid *

printf c formatting




printf C . . , , , , , . , , . , . , , "%08d", .

.

. . "e", "f", "a", "E", "A" "F" . , , , . : . , "%4.8s" , , .

, , "-" "%". .

, printf . : "", "d", "u", "i", "x" "X". "l", – "h". , short unsigned int "%ld" "%hu" .

hshort unsigned short
llong unsigned long
Llong double

1. printf C :

formatted output printf c




2. :

printf("");

3. :

examples of printf c




, , , . printf C, :

printf c examples




, , , .

scanf

scanf c format




scanf . printf scanf C "stdio.h".

scanf("format specifiers",&value1,&value2, ...);

c printf format




A simple example of working with the scanf function:

#include <stdio.h>

int main () {

int a;

float b;

scanf ("% d% f", & a, & b);

}




All Articles