ʴСѺ

㹡ʴ͡ҧ˹Ҩ
㹡ѺŨҡ
1. printf() 1. scanf()
2. putchar() 2. getchar() getch()
3. puts() 3. gets()

ʴ͡ҧ˹Ҩ
            ʴŢ͡ҧ˹Ҩö ¡Ϳѧѹҵðҹҫ
printf()
           printf 繤觾鹰ҹش㹡ʴŢŷءԴ͡ҧ˹Ҩ Ҩ繨ӹǹ( int ) , ȹ ( float ) , ͤ ( string ) ѡ ͡ҡѧդ״٧ Ҷ˹ͨѴٻẺʴºͧա ٻẺ¡ printf ʴѧ

printf( format , variable);

format : ŷͧʴ͡ҧ˹Ҩ¢Źͧ¹ͧ ŷöʴ 2 ͤ Фҷ㹵 觶繤ҷ㹵õͧʤǺٻẺçѺԴͧŷ㹵ù鹴
variable : ͹ԾͧùӤʴçѺʤǺٻẺ˹

ʤǺٻẺʴŤҢͧ͡ҧ˹Ҩ ʴѧ

ʤǺٻẺ

ùҹ

%d

ѺʴŤҢͧêԴӹǹ ( int, short, unsigned short, long, unsigned long)

%u

ѺʴŵŢӹǹǡ ( unsigned short, unsigned long )

%o

Ѻʴ͡ٻẺͧŢҹỴ

%x

Ѻʴ͡ٻẺͧŢҹԺˡ

%f

ѺʴŤҢͧêԴӹǹȹ ( float, double, long double )

%e

ѺʴŵŢȹ͡ٻẺͧ ( E e ) ¡ѧ ( float, double, long double )

%c

Ѻʴѡ 1 ( char )

%s

ѺʴŢͤ ( string ѡҡ 1 )

%p

ѺʴŵǪ˹ ( pointer )

ҧ printf ʴŢͤ͡ҧ˹Ҩ

ǹҧ printf ʴŨҡҢͧ͹Ծäӹdz͡ҧ˹Ҩ ʴѧ
¡˹

ʴºѡФǺʴ
͡ҡѧöѴٻẺʴºҡ â鹺÷Ѵѧʴͤ ҧͤ ѡФǺʴѺ printf ҫ ѡФǺʴٻẺ¡ѹ ѧʴ仹

ѡФǺʴ

\n

鹺÷Ѵ

\t

鹪ͧҧ 1 (6 ѡ)

\r

˹鹺÷Ѵ

\f

鹪ͧҧ 1 ˹Ҩ

\b

źѡش͡ 1

ùѡФǺʴ ҵͧ¹ѡФǺʴͧ ѧʴҧ仹

ǺҴ鹷ʴ
㹡ʴ鹷ʹաѺͤ Ҩʴͤ HELLO 5 ѡ ШѴ鹷ʹѺ 5 ѡ ѧʴٻ仹

H

E

L

L

O

ö鹷㹡ʴͧ ˹ʴͤ HELLO 㹾鹷袹Ҵ 8 ѡ ʴͤԴҹҢͧ鹷ͧ ¨鹾鹷ҧҧҹա 3 ͧ ѧٻ

 

 

 

H

E

L

L

O

Ըա˹Ҵ鹷ʴ ŢҴͧ鹷ͧѧͧ % ʤǺٻẺ ѧʴҧ仹

㹡óշͧ¹ҡʴŪԴͺҹԴͺҹ᷹    ö
ͧ   -   ˹ҵŢкآҴ鹷 ѧʴҧ仹

Ǻ˹觵Ţѧشȹ
͡ҡ㹡ʴŵŢѧشȹ   Զ˹    ʤǺٻẺ %f ʴŢȹ 6 ˹ 㹡óշҵͧõѴʴŢѧشȹҷ ( 2 3 ˹) ö˹仡ѺʤǺٻẺ ѧ仹

% . nf

n : ӹǹŢѧشȹͧʴ

ҧʴŨӹǹȹ ·աá˹˹觷ȹ ʴѧ

putchar()
㹡ʴŵѡѡ ( char ) ͡ҧ˹Ҩ ͡ҡ printf Ѻ˹ʤǺٻẺ %c ö¡Ѻʴѡѡ੾ա ¤觹鹤 putchar() ٻẺ¡ ѧʴ仹

putchar(ch);

ch : ѡѡ¹ͧ c' ͵êԴ char

ҧ putchar() 㹡ʴѡ͡ҧ˹Ҩ ʴѧ

puts()
繤ѺʴŢͤ͡ҧ˹Ҩ ٻẺ觴ѧ

puts(str);

str : ͤ¹ͧ ͵÷红ŪԴͤ

ҧҹ puts() 㹡ʴͤ͡ҧ˹Ҩ ʴѧ

ѺŨҡ
÷ӧҹͧǹ˭ѡ繡§ѺẺ 2 ȷҧ 蹡 Ҥͧʴš÷ӧҹ͡ҧ˹Ҩ ҤͧѺŨҡҷҧ 㹡ûżŢͧ ҤͧѺŨҡ ҫա˹пѧѹҵðҹ¡ ǡѺҤͧʴ ´ͧҹ
scanf()
ҫ ѺŨҡö¡¡ѧѹ scanf() 繿ѧѹҵðҹѺѺŨҡ öѺء Ҩ繨ӹǹ ( int ) , ȹ ( float ) ,ѡ ( char ) ͤ͢ ٻẺ¡ scanf() ¡Ѻ¡ printf() ѧʴ仹

scanf(format , &variable) ;

format : ʤǺٻẺ ͡˹ԴͧŷѺҨҡ ʤǺٻẺشǡѺʤǺٻẺͧ printf()
variable : ÷纤ҢŷѺҨҡ ªԴͧèеͧçѺʤǺٻẺ˹ ͡ҡ ˹Ҫͧ͢èеͧ˹Ҵͧ & ¡鹵ʵԧѺ红ͤҹ鹷ͧ˹Ҵͧ &

ҧҹ scanf() ѺŨҡ ʴѧ

getchar() getch()
2 觹ѺŻѡ( char ) ٻẺ¡觴ѧ

ch = getchar();
ch = getch();

ch : êԴ char 纤Ңͧѡ͵ѡ÷Ѻ

֧ҷ駤 getchar() getch() ѺѺŪԴѡ͹ѹ 2 觹դᵡҧѹç getchar() ͻ͹ѡ ͧ <Enter> ֧СѺ价ӧҹ еѡзһ͹ʴ繺˹Ҩʹ ǹ getch() ͧ <Enter> §һ͹ѡ 1 СѺ价ӧҹͷѹ еѡзһ͹ʴ

ҧ¡ getchar() ѺѡҨҡ ʴѧ

š÷ӧҹͧѧࡵ ҵͧ <Enter> ѧҡ͹ѡ ͡ҡѡ÷͹ʴҺ˹Ҩʹ
ҡ ¹ҡ getchar() getch() Ѿҡ÷ӧҹʴѧ

ѧࡵ getch() ͧ <Enter> ѧû͹ѡ Ш繵ѡ÷һ͹ʴҺ˹Ҩ
gets()
͡ҡ㹡ѺŪԴѡ͵ѡ Ѻͤҡ촡դ¡蹡ѹ gets() ٻẺ¡ѧ仹

gets(str);

str : Ѻ红ͤѺҨҡ 觨еͧҧ͹¡ gets()

ҧ¡ gets() ѺͤҨҡ ʴѧ


Ẻ֡Ѵ