问题描述
C历史问题在这里.为什么C函数putc
需要第二个参数,如
C history question here. Why does the C function putc
require a second parameter like
putc( 'c', stdout ) ;
看跌期权更方便
puts( "a string" ) ;
msvc ++中有一个功能
There is a function in msvc++
putchar( 'c' ) ;
哪种工作方式可能会期望putc
起作用.我以为putc
的第二个参数是能够将putc
定向到文件,但是为此有一个功能fputc
.
Which works the way one might expect putc
to work. I thought the second parameter of putc
was to be able to direct putc
to a file, but there is a function fputc
for that.
推荐答案
int putc ( int character, FILE * stream );
向流中写入一个字符,并向前移动位置指示器.
因此,它是比putchar
更通用的函数其他功能可以基于此,例如
Writes a character to the stream and advances the position indicator.
So it is a more generic function than putchar
Other functions can be based on this e.g.
#define putchar(c) putc((c),stdout)
根据Kernighan的书putc
与fputc
等效,但是putc
可以实现为宏,而putc 可能不得不多次评估其流参数.
我已经读过,据说两者都存在是为了向后兼容,但是不确定这是否有效
According to Kernighan's book putc
is equivalent with fputc
but putc
could be implemented as a macro and putc may have to evaluate its stream argument more than once.
I have read that supposedly that both exist for backward compatibility, but not sure if this is valid
这篇关于putc需要stdout,而puts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!