stdout, stdin 에 관하여

asleea의 이미지

printf("") 와 fprintf(stdout, "");

scanf("") 와 fscanf(stdin, "");

의 차이가 먼가요 .?

세벌의 이미지

많아요.

shint의 이미지

Visual C 에서 F11 눌러보니까. 이런 소스가 나오네요.
차이점은. 인자값을 파일 포인터'로 사용하느냐. 사용하지 않느냐. 입니다.

int __cdecl printf (
const char *format,
...
)
/*
* stdout 'PRINT', 'F'ormatted
*/
{
va_list arglist;
int buffing;
int retval;
va_start(arglist, format);
_ASSERTE(format != NULL);
_lock_str2(1, stdout);
buffing = _stbuf(stdout);
retval = _output(stdout,format,arglist);
_ftbuf(buffing, stdout);
_unlock_str2(1, stdout);
return(retval);
}

int __cdecl fprintf (
FILE *str,
const char *format,
...
)
/*
* 'F'ile (stream) 'PRINT', 'F'ormatted
*/
{
va_list(arglist);
REG1 FILE *stream;
REG2 int buffing;
int retval;
va_start(arglist, format);
_ASSERTE(str != NULL);
_ASSERTE(format != NULL);
/* Init stream pointer */
stream = str;
_lock_str(stream);
buffing = _stbuf(stream);
retval = _output(stream,format,arglist);
_ftbuf(buffing, stream);
_unlock_str(stream);
return(retval);
}

int __cdecl scanf (
const char *format,
...
)
/*
* stdin 'SCAN', 'F'ormatted
*/
{
int retval;
va_list arglist;
va_start(arglist, format);
_ASSERTE(format != NULL);
_lock_str2(0, stdin);
retval = (_input(stdin,format,arglist));
_unlock_str2(0, stdin);
return(retval);
}

int __cdecl fscanf (
FILE *stream,
const char *format,
...
)
/*
* 'F'ile (stream) 'SCAN', 'F'ormatted
*/
{
int retval;
va_list arglist;
va_start(arglist, format);
_ASSERTE(stream != NULL);
_ASSERTE(format != NULL);
_lock_str(stream);
retval = (_input(stream,format,arglist));
_unlock_str(stream);
return(retval);
}

//기타 참고 링크
http://promisej7.tistory.com/252
http://blog.naver.com/mr_null?Redirect=Log&logNo=90040347935
http://the__g.blog.me/140157144045

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com