fflush(fp)为什么没成功地将缓冲区未读写的内容发送到fp指定文件中?
书上说fflush(fp)将缓冲中未读写的数据发送到fp指定的文件中,为什么我的程序不成功,是解有误吗?
如我输入abc,此时ch被赋值为a,bc应该发送到文件中去不是吗?但是我打开文件时什么也没有呀。
#include "stdafx.h"
#include
#include
int main(void)
{
char ch;
FILE *fp;
fp = fopen("f:\\123.txt", "w");
if(fp == NULL)
{
printf("Can not open the file.\n");
}
scanf("%c", &ch);
printf("%c", ch);
fflush(fp);
fclose(fp);
return 0;
}
------解决思路----------------------
你的想法还真是特别, 没有读的字符就帮你发送到文件中....
------解决思路----------------------
man fprintf
------解决思路----------------------
#include
#include
int main(void)
{
char ch;