/ C.
getchar()
:
getchar();
. :
char c; //
int c;
c = getchar();
putchar()
:
putchar(c);
( ) .
printf()
:
printf(Control, arg1, arg2,..., argn);
. arg1, arg2,..., Argn . Control - , arg1, arg2,..., Argn, - arg1, - arg2 . . , , , . .
: - '%' :
- d - ( );
- o - ;
- x - ( a, b, c, d, e, f);
- - ( , B, C, D, E, F);
- U - ;
- - ;
- s - ; , , ( );
- - float double : [-]m.nnnnnn e[+-]xx, n . 6;
- E - , e, E ;
- f - float double : [-] Mmm.nnnnnn, n . 6;
- g - %e, %f: , . ;
- G - , g, E , e;
- n - ;
- p - . '. XXXX: YYYY YYYY ( ).
( % - ) :
[] [] [. ] [F | N | h | l | L]
, , , . , , .
|
|
- ( ), , , , . :
- () - ( ) . , , , , ;
+ - : '+' '-';
- ', . չ ;
# - , . , # (), c, s, d, u, i, o, x, X # . e, E, f , ( '߹, ). g, G e, E, , .
, '+', '+'.
- .
: , , , '*': int. '*', Control, .
:
n - n . , n, - , , - ;
0n (, 04) - n . , n, ;
* ( d) - '*', Control, , .
߹ . , i = 2 :
printf("%*d\n", 5, i);
2 ( - ). 5 , , .
- . , . , :
- ;
- '*'.
, Control, ( ).
, , int.
, : , - . , :
|
|
printf ("%. * d \n", 2, 5, i);
2 5 . i = 5, 05: - .
, . 1.
, j = 6.28 printf ("%. F \n", j) - 6.
1.
: 1 - d, o, u, x, X; 6 - e, E; - g, G; - s; 䴹 - c | |
- d, o, u, x. e, E, f | |
n | n n . n, ( ) |
. () | f |
- , , , . . 2.
2.
F | p, s | |
N | n | |
h | d, o, u, x, X | short int |
l | d, o, u, x, X | long int |
l | e, E, f, g, G | double |
L | e, E, f, g, G | long double |
L | d, o, u, x, X | __int64 |
h | c, C | 1 |
l | c, C | 2 |
h | s, S | 1 1 |
h | s, S | 1 2 |
, long, d l, ld.
scanf()
:
scanf(Control, arg1, arg2,..., argn);
. , , () Control, arg1, arg2,..., argn. Control , printf (). arg1, arg2,..., argn - , : , . . ' - , , , & arg.
Control - , ': , .
- , (\t), (\n). , , , ( ). - ASCII, '%'. , , . :
%[*][][F/N] [h/l] _
'%' :
- * - ' : - . '*', , , .
: ( ), . , ߹ . , ߹ . '*', , , .
|
|
- scanf () printf ().
scanf (). , :
int i; float x; char m[100];
scanf("%2d %f %*d %2s", &i, &x, m);
:
56789 0123 4572
?
: 56789, 0123 4572. (%2d) . : i = 56. 789. %f. x = 789. 0123 , . 4572 %2s. m '45'.
sprintf()
:
sprintf(string, Control, arg1, arg2,..., argn);
printf (), , , string.
߹ .
sscanf()
:
sscanf(string, Control, arg1, arg2,..., argn);
scanf (), , , string. ߹ .
cprintf()
printf():
printf(Control, arg1, arg2,..., argn);
printf (). conio.h, :
#include <conio.h>
printf () , stdout (. . " / "), cprintf () ( '' ), .
printf (), cprintf () '\n' "\r \n" - ( '\n' ). , '\t' .
Win32 Win32 GUI. 廻 . textcolor () ( ) textbackground () ( ). , . 3.
3.
BLACK | ||
BLUE | ||
GREEN | ||
CYAN | ||
RED | ||
MAGENTA | ||
BROWN | ||
- | LIGHTGRAY | |
- | DARKGRAY | |
- | LIGHTBLUE | |
- | LIGHTGREEN | |
- | LIGHTCYAN | |
- | LIGHTRED | |
- | LIGHTMAGENTA | |
YELLOW | ||
WHITE | ||
BLINK |
, .
|
|
, , , :
textcolor(CYAN + BLINK);
:
textcolor(3 + 128);
cprintf () ( 5).
5
//--------------------------------------------------------------------#include <vcl.h>
#include <conio.h>
#include <stdio.h>
int main(void) {
/* 1: ' (\r) (\n) */
/* */
clrscr ();
/* */
window (10, 10, 80, 25);
/* */
cprintf ("Hello world \ r \ n");
/* : */
getch ();
/* 2: 9- */
int i, j;
clrscr ();
for (i = 0; i <9; i + +) // 9 {
for (j = 0; j <80; j++)
cprintf ("C");
printf ("\ n");
textcolor (i + 1); //
textbackground (i); //
}
getch ();
clrscr ();
// 3:
textbackground (YELLOW);
textcolor (CYAN + BLINK); //
cprintf ("Hello! \r \n");
getch ();
return 0;
}
gets()
:
gets(s);
s, char *s char s[].
puts()
:
puts(s);
s ().
s char * s char s [].
cputs()
:
puts(s);
s (s char * s char s []). . textcolor (), - textbackground () (. cprintf ()). conio.h.
gotoxy()
:
gotoxy(x, y);
(x, y) , - , y - . int ( !). conio.h. gotoxy () 6.
6
//--------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include <conio.h>
//--------------------------------------------------------------------#pragma argsused
int main(int argc, char* argv[]) {
clrscr();
gotoxy(35, 12);
cprintf("Hello, world");
getch();
}
clrscr()
:
clrscr();
, textbackground (). 7.
7
//--------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include <conio.h>
//--------------------------------------------------------------------#pragma argsused
int main(int argc, char* argv[]) {
textcolor(YELLOW);
textbackground(YELLOW);
clrscr();
gotoxy(35, 12);
cprintf("Hello, world");
getch();
}
window()
:
window(x1, y1, x2, y2);
, (x1, y1) - , (x2, y2) - . int.
/ ++
++ , /.
- ios . / ++, ' :
#include <fstream>
fstream istream ostream. ifstream fstream. fstream / ( -) .
ifstream, fstream - () ( ). , istream, ostream cin, cout, cerr, / - , , , . , fstream ߹ , /.
|
|
/ (<<) (>>). , int, ++ .
, - ' , ( /, , . .). ' open (), , / (fstream, istream, ostream). , , , . , , ( ), ostream:
ostream exp;
exp.open (). : ' , , : , .
, - (<<, >>). exp ostream, , :
exp << " " << i << j << endl;
i, j - (, int i; float j;), endl - .
, , ' , ' . , "".
close () , , open (). :
exp.close ();