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区别程序例:
1 #include <stdio.h>
2 int main(void)
3 {
4     char msg[] = "Hello world\n";
5     int i = 0;
6     while (msg[i])
7     putc(msg[i++],stdout);
8     return 0;
9 }

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

posted @ 2018-03-13 15:59  路人浅笑  阅读(1406)  评论(0编辑  收藏  举报