336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 

1. conio.h 에 포함 되어 있다.

2. 아스키 코드값을 받아 콘솔 화면에 출력한다.


중요!!!

visual studio 2010 이상 쓰시는 분은 그냥 putch 이나 getch 쓰시면 에러가 나거나 경고 메시지가 나옵니다. 그럴때는 당황하지 말고 앞에 _(언더바)  하나 붙여주세요^^



원형 


void putch( int _Ch );

void _putch( int _Ch );



소스 코드 : main.c


#include <stdio.h>

#include <conio.h>


#define ESC 27 //종료 값


#define  W  'W'

#define  w   'w'


#define  S 'S'

#define  s 's'



#define  A 'A'

#define  a 'a'



#define  D 'D'

#define  d 'd'


#define TRUE 1

#define FALSE 0


int FrameMove(void);

void Print(int nKey);


int g_nKey = 0; // 전역 키값


int main(void)

{


//do

//{

// printf("입력 대기\n");

//}while(FrameMove());

while (FrameMove())

{

Print(g_nKey);

}


printf("GAME OVER");

return 0;

}


int FrameMove(void)

{

int nReturnValue = TRUE;


g_nKey = _getch();


if (g_nKey == ESC)

{

nReturnValue = FALSE;

}



return nReturnValue;


}


//_CRT_SECURE_NO_WARNINGS

//error C4996 


void Print(int nKey)

{

switch (nKey)

{

case W:

case w:

_putch('\t');

_putch(W);

_putch('\n');

break;


case S:

case s:

_putch('\t');

_putch(S);

_putch('\n');

break;

case A:

case a:

_putch('\t');

_putch(A);

_putch('\n');

break;

case D:

case d:

_putch('\t');

_putch(D);

_putch('\n');

break;


default:

_putch('\t');

_putch('X');

_putch('\n');

break;

}

}


결과


#c언어, #C언어입문, #프로그램입문, #게임프로그램, #putch, #_putch

'Programing - C > C Basic grammar ' 카테고리의 다른 글

054 printf를 이용하자  (0) 2017.07.27
053 scanf, scanf_s  (0) 2017.07.27
051 getch 함수  (0) 2017.07.27
050 매크로 함수 이해하기  (0) 2017.07.27
049 선언과 헤더파일 만들기  (0) 2017.07.27

+ Recent posts