功能:
->fgetc :从流中读取字符
->fputc:把字符写入指定文件中
格式:
int fgetc(FILE *stream)
注:这个函数的返回值,是返回读取的一个字节,如果读到了文件末尾或者读取文件失败时会返回EOF。
int fputc(int c,FILE *stream)
注:这个函数的返回值,返回的时写入问价的字符的ASCII码值,出错是,返回EOF(-1),当正确写入一个字符或一个字节的数据后,文件内部指针将会自动的往后移一个字节的位置。
代码示例:
#include<stdio.h>
#include<stdlib.h>
int main(int argc,const char *argv[])
{
FILE *fp = NULL;
char ch;
fp = fopen("/user/qingyun/desktop/demo.txt","w");
if(NULL == fp)
{
printf("input error");
exit(1);
}
ch = fgetc(stdin);
while(ch != EOF)
{
fputc(ch,fp);
ch = fgetc(stdin);
}
fclose(fp);
return 0;
}