c·c++/c 프로그래밍

일정시간이 지나면 scanf를 취소하기.

바로이순간 2012. 11. 14. 14:48

#include <stdio.h>

#include <time.h>

#include <conio.h>

int main() {

  int sec=10, duration, acc=0; 

  int x, y, n;

  char ch;


  while(!kbhit()) {

    duration = (clock()) / CLOCKS_PER_SEC;

    if(duration>=acc) {

      printf("%d\n", sec-acc);

      // 입력된 시간보다 증가한 시간이 더 많으면 반복문을 빠져나옴

      if(acc>=sec) break;

      acc+=1;

    }      

  }

  if(acc>=sec) printf("[finish]");

  else {

    scanf("%d", &x);

    printf("[%d]", x);

  }


  return 0;

}