网友您好, 请在下方输入框内输入要搜索的题目:
请补充main 函数,该函数的功能是:把文本文件B中的内容追加到文本文件A的内容之后。
例如,文佃的内容为“I’m ten.”,文件A的内容为“I’ m a student!”,追加之后文件A的内容为“I’m a student !I’m ten.”
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数main 的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio, h>
include<conio. h>
define N 80
main()
{
FILE *fp, * fp1, *fp2;
int i;
char c[N] ,t, ch;
clrscr ();
if ((fp=fopen ("A. dat ", "r") ) == NULL)
{
printf ("file A cannot be opened\n");
exit (0);
}
printf("\n A contents are : \n\n");
for (i=0; (ch=fgetc (fp)) !=EOF; i++)
{
C [i]=ch;
putchar (c [i]);
fclose (fp);
if((fp=fopen ("B. dat", "r") )==NULL)
{
printf ("file B cannot be opened\n");
exit (0);
}
printf("\n\n\nB contents are : \n\n");
for (i=0; (ch=fgetc (fp)) !=EOF; i++)
{
c [i] =ch;
putchar (c [i]);
}
fclose (fp);
if ( (fp1=fopen ("A.dat" ,"a"))【 】(fp2
=fopen ("B. dat", "r") ) )
{
while ( (ch=fgetc (fp2)) !=EOF)
【 】;
}
else
{
printf("Can not open A B !\n");
}
fclose (fp2);
fclose (fp1);
printf ("\n***new A contents***\n\n");
if ( ( fp=fopen ("A. dar", "r") )==NULL)
{
printf ("file A cannot be opened\n");
exit (0);
}
for (i=0; (ch=fgetc (fp)) !=EOF;i++)
{
c [i] =ch;
putchar (c [i] );
}
【 】;
}
参考答案