리눅스 \r 출력관련.
글쓴이: ezisis / 작성시간: 목, 2012/03/29 - 9:23오전
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<unistd.h>
#define MAX_COUNT 10
int main()
{
FILE *fp;
char *ch ="+-"; // element unit (positive or negative)
char op;
int i=0;
char CR = '\r';
int people;
if((fp=fopen("data.txt","w"))==NULL){ //data file
printf("file open error\n"); //exception handling - file open error
}
printf("\n");
srand(10);
for(i=0;i<MAX_COUNT;i++){
people = (rand()%10)+1;
op = ch[people%2]; //choseing unit (pos or neg)
printf("\r [out] %c %2d people",op,people);
sleep(1);
}
return 0;
}한행만 이용하여, 인자만 다른 같은 형태의 반복적인 출력을 해주는 프로그램입니다.
이전의 출력을 지워주기 위해 '\r'을 사용했습니다.
같은 형태로 window 에서 컴파일하니, 잘만되는데,
리눅스에서는 (gcc - fedora15) 출력조차 안되네요;;;;
출력 형태가 문제인가 생각해서 \r 의 위치를 바꿔보고 다른 방식으로 출력해봤는데, 여전히 출력조차 안됩니다. (프로그램은 정상실행)
뭐가 문제인지 통 모르겠네요;;
Forums:


sleep(1); 전에 fflush(stdout);
sleep(1); 전에 fflush(stdout); 을 추가해보세요. 출력 버퍼를 비우지 않고 sleep() 해버려서 그렇습니다.
감사합니다.
덕분에 해결했습니다. 출력버퍼를 지우는 습관을 키워야겠군요 ;; 아무튼 답변 감사드립니다.
댓글 달기