文件2向文件中输入字符数据——fputc

文件1向文件中输入数据

向E:\大一下C语言\输入文件\exp01.txt中写入数据

程序

#include<stdio.h>
#include <cstdlib>/*或者#include <stdlib.h>*/
main()
{
	FILE *fp;
	char ch;
	if((fp=fopen("E:\\大一下C语言\\输入文件\\exp01.txt","w"))==NULL)
	{
		printf("cannot openfile");
		exit(0);
	}
	ch=getchar();
	while(ch!='#')
	{
		fputc(ch,fp);
		ch=getchar();
	}
	fclose(fp); 
}

2设计思路

动用fptc(,)来将数据写入文件

3)本题调试过程碰到问题及解决办法

问题:
在程序中未加#include 或者#include <stdlib.h>(二者在DEV C++中可以互换stdio.h也可以用cstdio互换)
出现[Error] 'exit' was not declared in this scope
解决:没有加头文件#include 或者#include <stdlib.h>会导致出现计算机不能判断函数

posted on 2019-03-05 20:07  凯*凯  阅读(152)  评论(0编辑  收藏  举报

导航