저는 C 프로그래밍을 처음 접했고 간단한 tic-tac-toe 게임을 만들어야하는이 작업을했습니다.간단한 tic tac toe 입력에서 fflush (stdin)을 사용하는 방법은 무엇입니까?
배열과 루프가있는 빈 보드를 만들었습니다. 이제 사용자의 입력을 받아서 'X'/ 'O'를 게시판에 삽입해야합니다.
#include <stdio.h>
#include <stdlib.h>
int main()
{
//Declare the variables
//Create the board
//Initialize the board with all blanks
//Print to screen
//Prompt user for letter 'X', 'O' or 'q' to quit
//declare the variables
char board[3][4], input;
int rows, columns;
do
{
//create the board
for (rows = 0 ; rows <3 ; rows++)
{
for (columns = 0 ; columns < 4 ; columns++)
{
//Initialize array to blanks (' ')
board[rows][columns] = '|';
//print to screen
printf("%c\t", board[rows][columns]);
}
printf("\n\n\n");
}
printf("Hit X or O. 'q' to quit\n\n");
scanf("%c", &input);
} while (input != 'q');
}//end main
작업은 내가 그것이 무엇이며 어떻게 그것을 사용하는 :(
내가 분명히 아무 생각이 키보드 버퍼를 지우려면이 코드fflush(stdin)
을 사용할 수 있습니다 말한다 : 여기
코드입니다
그 코드에 대한 몇 가지 연구를하고는 기존의 입력을 대체하고, 만약 내가 잘못 정정 해줘 outputs..please 보인다.
그래서 어떻게 내 현재의 경우 fflush(stdin)
을 사용할 수 있습니까?
샘
키보드 버퍼가 지워졌으므로 scanf 앞에 놓고 입력을하기 전에 버퍼를 지워야합니다. –