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:
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
printf C . printf vprintf stdout, fprintf vfprintf , snprintf, sprintf, vsnprintf vsprintf . , .
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
, , : , , , , . , , . , , .
"%" , . , .
printf C . , , . , , , .
, , "%m$" "%" "*m$" "*", m, , ( ).
stream | |
buffer | |
bufsz | , : - bufsz-1, |
format | , , |
, | |
- | |
+ | , , "+" ( "-" ) |
0 | , , . , . . "0" , "-" |
space | , , , . "space" , "+" |
# | |
| printf C | |
% | "%" | |
c | . unsigned char. "l" | unsigned char |
s | . char | char * |
d
i | | int |
o | | unsigned 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 * |
p | | void * |
printf C . . , , , , , . , , . , . , , "%08d", .
.
. . "e", "f", "a", "E", "A" "F" . , , , . : . , "%4.8s" , , .
, , "-" "%". .
, printf . : "", "d", "u", "i", "x" "X". "l", – "h". , short unsigned int "%ld" "%hu" .
| |
h | short unsigned short |
l | long unsigned long |
L | long double |
1. printf C :
2. :
printf("");
3. :
, , , . printf C, :
, , , .
scanf
scanf . printf scanf C "stdio.h".
scanf("format specifiers",&value1,&value2, ...);
A simple example of working with the scanf function:
#include <stdio.h>
int main () {
int a;
float b;
scanf ("% d% f", & a, & b);
}