fputc
函数名: fputc
功 能: 送一个字符到一个流中
函数头:属于输入输出函数,在C语言中,包含在文件stdio.h中。ANSI标准。
用 法: int fputc(int ch, FILE *stream);
程序例:
#include <stdio.h>
int main(void)
{
char msg[] = "Hello world";
int i = 0;
while (msg&&(i<strlen(msg)))
{
fputc(msg, stdout);
i++;
}
return 0;
}
程序例二:
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fpout;
char ch;
if((fpout=fopen("file_a.dat","w"))==NULL)
{
printf("Error!
");
exit;
}
ch=getchar();
for(;ch!='#';)
{
putc(ch,fpout);
ch=getchar();//不能仅写getchar();
}
fclose(fpout);
}
备注:putc()功能与用法与之完全相同。