fputc和putc和putchar函数的用法

时间:2023-03-09 18:17:34
fputc和putc和putchar函数的用法
功 能: 输出一字符到指定流中
putc()与fputc()等价。不同之处为:当putc函数被定义为宏时,它可能多次计算stream的值。
关于fputc():
原型:int fputc(char ch,FILE*fp)
功能:在fp所指向的文件的当前读写位置写入一个字符。写入字符成功则函数返回值为该字符的ASIIC值,写入字符不成功则返回值为EOF。
向文件写入一个字符后,文件读写位置指针向后移动一个字节。
与putc一样一般用法为“fputc(ch,fp)”,包含在头文件“stdio.h”中。
用 法: int putc(char ch, FILE *fp);
与putc区别程序例:
 #include <stdio.h>
int main(void)
{
char msg[] = "Hello world\n";
int i = ;
while (msg[i])
putc(msg[i++],stdout);
return ;
}

putchar(ch) 相当于 putc(ch,stdout);