ũ ι° ðԴϴ.  ҽ  ̴?

̹   Լ ؼ ˾ƺ ϰڽ

.  ôٰ տ ? ִ ܾ Լκп

漳  Ͻñ..

׷ !

////////////////////////////////////////////////////////////////////

clrscr()

ʿ ش: conio.h

?: void clrscr(void);

켱   .

#include <conio.h>

main()
{
    printf("HAHAHA..");
    getch();
    clrscr();
    getch();
}

Ű ȭ鿡 HAHAHA.. Ÿϴ. ƹŰ  ȭ 

 ٽ ƹŰ  ϴ.

getch()Լ ִ ´ Ű澲ð ׳ ŰԷ ޴ 

 ϼ.

׷ ߿ clrscr()Լ   ϰڽϴ.

clrscr()Լ clear screen(³?) Դϴ. , ȭ  

ε, clrscr()Լ ?ڰ , ?ȯ ϴ.

׷Ƿ, ׳ clrscr(); ̶  ȭ ϴ.

/*

: ̶ Լ ȯ μ  Ϸ ˷ֱ

ؼ ϴ ε, Ϸ   μ ڷ Լ

 ڵ ڷ  ˼ֽϴ.   쿡

 ޼ Ե.

   Լ ȯ ڷ ȯ , μ ڷ

 ˼ֱ  ſ մϴ.

)

void clrscr(void);

̰ clrscr()Լ ε, ̰  ,

ȯ | Լ | ();
-------+--------+---------
 void  | clrscr | (void);

̷ Ǵµ, clrscr()Լ  ȯκп void

 ? ⼭ C ڷ 캸,

[C ڷ ]

char  : 
int   : 
float : Ǽ
double: Ǽ
void  :  

̷ 5ε, void  ٰ ֱ..

Ǹ ġä̰? ׷ϴ. clrscr()Լ ȯ  

ʽϴ.  ںκп void ? , clrscr()Լ ȯ

 , ڵ ϴ.   ,

clrscr()Լ  clrscr()Լ  ڷᳪ () ʿ

, ȯ ٴ Դϴ. ٽøϸ clrscr()Լ ׳

clrscr();̷Ը ġ ȴٴ Դϴ. ߰ȣȿ ͵  ʿ䰡

 ־ ʵǸ, ȯ  ġȯ̳ ǹ 

  ִٴ Դϴ. ϼ̳?  ..^^; 

ø ּ..  å ״ 貸 帱´..^^

: Լ ޵Ǵ , ߰ȣ '(' ')'̿ ִ  ڶ 

ϴ. ڴ Լ ޵ǰ Լ ڸ    Ѵ

ȯ. ڴ ','(ǥ) մϴ.

1)

void gotoxy(int x, int y);
---- ------^-----^ -----^
1   2  | 4 |  6 |
          3   5    3

,   ϰڽϴ.

켱.. 1. void ?  κ Լ ȯ ٴ

 ˼ֽϴ.

2. gotoxy ? ̰ Լ ̸Դϴ.

3. 3 ΰ?  '(' ')' gotoxy Լ Ÿ ߰ȣ

Դϴ.

4. ù° ڷ,

int x

.. պκп int ? ̰ɷ 츮  Լ ù° 

 ڷ ̶  ˼ֽϴ. ׷  ڷ 

    ? װ Լ x   

 ϱ⶧ε..

  ҽ ִٰ ϸ..

#include <stdio.h>

int kim(int num); <-̰ kim()Լ Դϴ.

main()
{
    int i;

    i=kim(10); <-B.

    printf("%d",i);
}

int kim(int num); <-A. --+
{                            |---kim()Լ.
    return(num*num);         |
}                          --+

 kim()Լ ڰ 10?  10̶ ڴ A kim()Լ

޵Ǿ ϴµ, ׳ ޵Ǵ° ƴ϶, num̶  ġȯ

Ŀ num̶  ޵Ǵ Դϴ.

kim()Լ ޵ num  ϰ ٽ  , ȯմϴ. 

 ȯ(num ,  100) kim()Լ ΰ,  B ȯ

ϴ.

׷..

i=kim(10);

̺κ

i=100;

 ٲϴ.

Ŀ printf()Լ ؼ 100 ȭ鿡 µǴ .

5. ̰ ڸ ϱ  ǥԴϴ.

6. ̰ gotoxy()Լ ι° Դϴ.  ڵ ù° ڿ 

int()̶  ˼ְ ڰ yԼ ġȯ Ŀ Լ 

޵ȴٴ  ˼ֽϴ.

⼭  !  int Hero(int name); Լ ȯ 

ȯ ڷ, ׸  ڷ?

2)

num=10;
printf("%d",num);

 "%d" num printf()Լ Դϴ.

, printf()Լ "%d" num̶ ڸ   Ƽ ȭ鿡

10 ϰ Ǵ .

ȯ(Ͱ): ȯ Լ  ڸ Լ  

մϴ. ȯ ִ Լ  Լ ִµ ȯ  Լ

   ˼ֽϴ. ڼ   漳κ 

ñ..

)

char ch;
ch=getch();
printf("%c",ch);

 getch()Լ Ű忡  ڸ Է¹ް ׹ڸ ȯմϴ.

,  ҽ getch()Լ  ´  ٰ Ҽ

ϴ.

 A ٸ,

char ch;
ch='A';
printf("%c",ch);

Ǵ

char ch;
ch=65;
printf("%c",ch);

̷° ȴٰ Ҽֽϴ.

ٽ ڸ ȯ ִ Լ Լ  , Լ ִ

ڸ ȯ . , Լ ġȯ̳ ǹ ־

,  Լ ȯ ġȯǰų ǹ꿡 Եȴ.

 Ҽֽϴ.  ? ƴٰ ǽô  ֽñ.

*/

////////////////////////////////////////////////////////////////////

randomize()

ʿ ش: stdlib.h  time.h

: void randomize(void);

켱   .

#include <stdlib.h>
#include <time.h>

main()
{
    randomize();
}

 Լ ȯ ڰ ϴ. ׷Ƿ ׳, randomize();ϸ 

ϴ.

 Լ ش 2 ʿѵ,  stdlib.h randomize()

Լ Ǿ ְ, time.h ʿ , randomize()Լ 

Լ ʱⰪ οҶ PC ð踦 ϴµ, ׶ time()̶

 Լ մϴ.  time()̶ Լ time.hȿ Ǿֱ 

.

randomize()Լ ߻Լ(random()̳ rand()) ʱⰪ ο

 Լμ   Ű ƹϵ Ͼϴ.

׷  Լ ? Ͻô е鵵 ǲ..  ش 

random()Լ  ..   ? ~

////////////////////////////////////////////////////////////////////

random()

ʿ ش: stdlib.h

: int random(int num);

켱   .

#include <stdio.h>
#include <stdlib.h>

main()
{
    printf("%d", random(100) );
}

random()Լ 0 num-1 ? ߻Ű Լε,  

 ϱ ,  ؼ   ϰڽϴ.

random()Լ 

int random(int num);

̷ Ǿִµ, 켱, ȯ  int  ?

int ̴ϱ random()Լ ڽ    ȯ

ٴ° ˼ֽϴ. ״, ںκ  int num̶ ? 

 random()Լ int,   (num) ʿ Ѵٴ 

ε, ٽϸ random()Լ  (num) ޾Ƽ װ

  ؼ ڽ   ,  ȯ ȯѴٴ 

˴ϴ.

⼭ random()Լ ǵǾִ stdlib.h  鿩 , random

()Լ ڽ Ѱܹ ,  num    

ִµ, ׽ (rand()%(num))̶ ֽϴ. ̰ Ǯ,

x % num , (x) (num)    

 Ǵµ, ⼭ Ǵٸ ߻Լ rand()  ˴ϴ. 

߿  װ ƴϹǷ ׳ Ѿ rand()Լ () 

Ųٴ ͸ ˰ ˴ϴ. · ߿Ѱ, rand()Լ ߻

Ų ,  x random()Լ ޵  num  

 random()Լ ȯ ٴ Դϴ. ,   

ư ô.

#include <stdio.h>
#include <stdlib.h>

main()
{
    printf("%d", random(100) );
}

ҽ random()Լ ߰ȣȿ 100̶ ?  100̶

ڸ random()Լ ڽ ڷ  num̶  ֽ

. ׷  ߻ (rand()%(num) ֽϴ. ׷,

  rand() % 100

= x % 100

= y

̷ Ǽ y 0 num-1   y źǴ Դϴ!!

׷ random()Լ   ҽ  ٰ Ҽֽϴ.

#include <stdio.h>
#include <stdlib.h>

main()
{
    printf("%d", y );
}

Ŀ printf()Լ %d y ٲ۴ ȭ鿡 ϰ ˴ϴ.

 46 Ա.   ̴? ׷,  ҽ 

 Ѻʽÿ. ׷  ҽ ߴ  ˰ ˴ϴ.

 Ƽ̽ϱ?

..    ? ̷ ߻Լ Ҽ ..

׷   ĺ ~

켱 ٽ random()Լ ߻ ô.

(rand()%(num))

⼭  rand()Լε..

 rand()Լ  ߻Ųٰ ?

׷, rand()Լ   ߻ų?

켱 rand()Լ randomize()Լ ο ߻Լ ʱⰪ(seed)

 ̷ ,   ؼ  ߻Ű ̴ϴ. ׷ 

,  ʱⰪ  ϴ  ƴ϶ (!)Դϴ. rand()Լ

߻ĵ н̹Ƿ        

  Ǵ°.. ׷ ٽ randomize()Լ  о ʽÿ.

randomize()Լ ߻Լ ʱⰪ οѴٰ ?  Ƽ̴

?

ᱹ 츮 random()Լ  ߻Ű  ,

1.߻û.

2.random()Լ, ߻ûȮ.

3.random()Լ γ߻ .(rand()%(num))

4.γ߻Ŀ rand()Լ ߻û.

5.rand()Լ, ߻ûȮ.

6.rand()Լ γ߻ , ߻ʱⰪ(seed)ã.

7.߻ʱⰪ(seed)  γ߻İ,  random()

 γ߻ rand()  κп ȯ.

8.random()Լ γ߻, rand()Լ ȯ   

 ߻İ,  random()  κп ȯ.

.. ̷ ؼ ߻ŵϴ. ⼭ randomize()Լ  ù

 ҽ ,

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main()
{
    randomize();
    printf("%d", random(100) );
}

̷ ˴ϴ.

̼ҽ ߻ 

0.randomize()Լ, ߻ʱⰪ(seed)  ο.

1.߻û.

2.random()Լ, ߻ûȮ.

3.random()Լ γ߻ .(rand()%(num))

4.γ߻Ŀ rand()Լ ߻û.

5.rand()Լ, ߻ûȮ.

6.rand()Լ γ߻ ,  ο ߻ʱⰪ(seed)

ã.

7.߻ʱⰪ(seed)  γ߻İ,  random()

 γ߻ rand()  κп ȯ.

8.random()Լ γ߻, rand()Լ ȯ   

 ߻İ,  random()  κп ȯ.

̷ ߻Ű Ǵµ Ź Ҷ randomizeԼ  

߻ʱⰪ οϹǷ    ʰ  () ߻

Ű Ǵ Դϴ. ׷  ذ ʰø ..^^

/*

:   Ģ  ߻ϴ  մϴ.

      ..   ڸ.. .. ..^^;; ڼѰ....

*/

////////////////////////////////////////////////////////////////////

kbhit()

ʿ ش: conio.h

: int kbhit(void);

 Լ Ű ȴ ʴȴ ˾Ƴ Լ, ڴ  ȯ

 ̶  ̹ ˰ְ?

ȯ ؼ ڸ, Ű  0̿  ȯϰ, Ű 

0 ȯմϴ.

, Ʊ      µ.. ⰳ

.. ׸..

(^^)_)_)_)_)_).. <-..( .)

>^)+++++++< <-ġ..( .)

*m~ <-~ ..(ȭ濡 .)

? ϳ..

Oo.. ī..                                    ! ~ ~

..    Ǯ̴..^^

  ?

#include <stdio.h>
#include <conio.h>

main()
{
    printf("Press any key to continue...");

    while(!kbhit()) ;

    printf("Bye-bye..");
}

   켱 ȭ鿡 Press any..  Ÿϴ. ׸

  ?  ƹŰ . ׷ Bye-bye.. 

 ϴ.

߿Ѱ 

while(!kbhit()) ;

ε. ǹ ,

!kbhit()

 ? 켱 kbhit()Լ Ǹ Ű ȴ ʴȴ 

ƺϴ. Ű ʴȴٸ 0,   ȯϰ .. ׷..ǽ

!0

̷ ˴ϴ. '!' ڴ   ٲٴϱ 0 ̹Ƿ !

ڿ   ٲϴ. ׷..

while(1) ;

̷ ˴ϴ.   ̵ǰ(C ǽĿ 0 , 0̿ (

κ1) ̶  ˰ð?) ݺ ˴ϴ. ?

ݺ ɰ ?

׷ϴ. ݺ Ƿ(Ȯ ؼ ȭ鿡 ǥõǴ° ϱ

..) ó ̴ ̴ϴ.

̰ ٷ ..^^;

#include <stdio.h>
#include <conio.h>

main()
{
    printf("Press any key to continue...");

    while(!kbhit()) ; <-̺κ!!

    printf("Bye-bye..");
}

Ű  kbhit() 1 ȯ ʴ ̻  ݺ ǰ, ȭ

鿡 ǥõǴ  Ƿ 츮Դ ó̴ Դϴ. 츮

 ϴµ ǻʹ CPU ǰ while ݺϴ .

(ϱ..-_-;;)

׷ ̷ ȿ  ϰ Ѵ  ?

 ..

ٷ getch()!! !!!!

////////////////////////////////////////////////////////////////////

getch()

ʿ ش: conio.h

: int getch(void);

Լ ٷ ȿ  ϰ ִ Լν  ٿ

ô.. .. .. -_-;;;

켱..  ..

int getch(void);

 Ƽ̰ Լ ȯ ̰ ڴ ϴ.

ȯ Ű 쿡 Ű ƽŰڵ带 ȯϰ, ȮŰ(?) (

Ű Ű(F1-F12))   0 ȯϰ ״ Ű ش

ϴ ĵڵ带 ȯմϴ. ⼭ ĵڵ忡    𸣴 

  ..--;;

̹  ҿ̴ϱ.. 5-6뿡 ..-_-;;

׸  Լ Ǹ Ű  ٴ.. 

 ϱ  kbhit()Լ ȭ ʿ..

.... ô.--;;

#include <stdio.h>
#include <conio.h>

main()
{
    printf("Press any key to continue...");

    while(!kbhit()) ;

    printf("Bye-bye..");
}

̷ ҽ~

main()
{
    printf("Press any key to continue...");

    getch();

    printf("Bye-bye..");
}

̷ ߽ϴ.(̰.. .. Ż..--)

 ҽ Ű.. Ȱ   ξ ȿ̶ ..

 ˾Ƶνñ..   ڸ..

main()
{
    char ch;

    printf("Press any key to continue...");

    ch=getch();

    printf("It's a %c.",ch);
}

̰ Ű  Ű  ǻͰ մϴ. ^^;

켱..  ch ?

׸ ƹŰ  ޼ ߰..

Է ٸ.. Ⱑ ߿!

ch=getch();

켱 getch()Լ Է ٸϴ. ƹŰ (ǵ ..)

getch()  Ű ƽŰ ȯ. ׷..

ch=(Ű ƽŰ)

࿡ A ..

ch=65; Ǵ ch='A';

̷ ǰ printf()Լ ϰ Ǵ . ׷  Լ Ѿ

?                            >>>--------------<> ~

////////////////////////////////////////////////////////////////////

gotoxy()

ʿ ش: conio.h

: void gotoxy(int x,int y);

 Լ Ŀ  ǥ ̵Ű Լν ũ 鶧

   Լ..

켱 Ͱ , ڰ 2 ֱ..

ù°  x 1-80  ؾϰ, ι°  

y 1-25  ؾմϴ.   ʰ  

Ұ  gotoxy()Լ õǰ, Ŀ ̵ ʽϴ.

Ŀ (10,10) ִ ¿ gotoxy(100,20);̷ Ѱ, gotox

y()Լ õǰ, Ŀ  (10,10) ֽϴ.

⼭ ǥü踦..

               <ȭ..>
1<--------------------------------------->80
+-----------------------------------------+1
|                                         |^
|                                         ||
|                                         ||
|                                         ||
|                                         ||
|                                         ||
|                                         ||
|                                         ||
|                                         |v
+-----------------------------------------+25

Ͱ  ̷  ׸.. ˼..TT

 ڸ..  ô   մϴ.  ̶

 ϸ  ȭ   ..

xǥ ʳ ǥ 1̰ ʳ ǥ 80Դϴ.

yǥ  ǥ 1̰, ǾƷ ǥ 25Դϴ.

Ѹ 80ĭ 25ĭε..

 ?

#include <stdio.h>
#include <conio.h>

main()
{
    gotoxy(10,10);
    printf("This is first location.\n");
    printf("This is second location.");
}

̰ Ű..

          xǥ10
  +---------|-------------------------------+
y |         |                               |
|         |                               |
ǥ|         |                               |
10----------This is first location.         |
  |This is second location.                 |
  |                                         |
  |                                         |
  |                                         |
  |                                         |
  +-----------------------------------------+

̷ ɴϴ.

, printf("This is first location.\n"); \n  Ű..
          xǥ10
  +---------|-------------------------------+
y |         |                               |
|         |                               |
ǥ|         |                               +--------------+
10----------This is first location.This is second location.|
  |                                         +--------------+
  |                                         |
  |                                         |
  |                                         |
  |                                         |
  +-----------------------------------------+

̷..--;;;; ٷ ɴϴ.

#include <stdio.h>
#include <conio.h>

main()
{
    gotoxy(70,20);
    printf("This is first location.");
}

̷ ϸ..

                               xǥ70
  +------------------------------|----------+
  |                              |          |
  |                              |          |
  |                              |          |
  |                              |          |
y |                              |          |
-------------------------------This is fir|
ǥ|st location.                             |
20|                                         |
  |                                         |
  +-----------------------------------------+

̷ ɴϴ.

  gotoxy();  Ƽ̴?

׷  Լ Ѿڽϴ.

////////////////////////////////////////////////////////////////////

exit()

ʿ ش: stdlib.h

: void exit(int status);

exit()Լ α׷ ü  ư ϴ ԼԴϴ.

 status Ż° ϰ Ǵµ..

status 0ΰ쿡  Ż , ޴  츦

ϰ, 1ΰ쿡  Ż,   츦 մϴ.

0,1 ΰ   𸣰ڰ.. .. ˾Ƽ ϴ.^^;;

 ..

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

main()
{
    for(;;) {
        if(kbhit()) {
            exit(0);
        }
    }
}

̰ Ű.. ƹϵ  Ͼϴ.

for(;;) κп ؼ ѷ  .

ݺ ǽ

if(kbhit())

 ִµ, kbhit() Ű  0 ƴ  ,  ȯ.

׷Ƿ ƹŰ ,

if(1)

̷ Ǽ   ǰ

exit(0);

 .. ׷ exit()   Ż ϰԵ˴ϴ.

 ϼ̳?

׷  Լ !

////////////////////////////////////////////////////////////////////

delay()

ʿ ش: dos.h

: void delay(unsigned milliseconds);

 Լ ̱..

ȯ .. !  ܾ..

unsigned unsigned int ٿ Դϴ. ..

int(̰͵  signed int  ܸ..) -32768~32767  

Ҽ ֽϴ. ..

unsigned int̷ ϸ.. 0~65535  Ҽ..

̵  ϴ. Ѵ 65536  ϰ ..

intٰ 100000(ʸ) ġȯϰ ½Ű.. ϰԵ

-31072 .. ̰.. ÷ο.. 帥(?) ϴµ..

 ڼ ˰ ź  ֽñ..

ư.. ߿Ѱ delay()Լ ڴ 0~65535 ڸ ؾ

Ѵٴ°Ͱ.. 1/1000   ϽŲٴ Դϴ..

׷..  ô.

#include <stdio.h>
#include <dos.h>

main()
{
    int i;

    for(i=0;i<10;i++) {
        printf("Hello, World.\n");
        delay(1000);
    }
}

̷ ϸ Hello, World. ܾ 1ʰ 10 ȭ鿡 Ÿ

Դϴ. ̷л δ 1/1000..    

..--;; ư.. ߿Ѱ.. α׷ ϽŲٴ°..

////////////////////////////////////////////////////////////////////

.. ̹ ´ ̰ɷ ڽϴ..

 ¿ Լ  ǿ   ̴

 ˾ƺ..  ũۿ .. ũ ˰

(âϱ..--) ü .. ϰڽϴ.

.. 21 ε.. .. 8ð 豺.. --;;

³߿ Ʋ  ּ..

 ñ  ź ּ.. δ㰮ð..

׸  3ö󰡴ϱ.. ݸϼŵ մϴ.. but, ..^^;;

׸.. Ÿ ¿   ްڽϴ.  ˰ ִ ̸

ּ ؼ  帮.. ׸.. 亯..  ٴ 

¶ Ƽ  帮ڽϴ. ¶  ñ.. 

..

////////////////////////////////////////////////////////////////////

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

û..

ϵ, α׷, ŷ   å ˰    

ּ..

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
