更多"已有文本文件test.txt,其中的内容为:Hello,everyon"的相关试题:
[填空题]已有文本文件test.txt,其中的内容为:Hello,everyone!。以下程序中,文件test.txt已正确为“读”而打开,由此文件指针fr指向文件,则程序的输出结果是______。
#include <stdio.h> main( ) FILE *fr; char str[40];
fgets(str,5,fr);
printf("%s/n,,str);
fclose(fr);
[填空题]已有文本文件test.txt,其中的内容为:Hello, everyone!(,与everyone之间没有空格)。以下程序中,文件test.txt已正确为“读”而打开,由此文件指针fr指向文件,则程序的输出结果是______。
#include <stdio.h>
void main( )
FILE *fr; char str[40];
……
fgets(str,8,fr);
printf("%s/n",str);
fclose(fr);
[填空题]已有文本文件test.txt,其中的内容为:I am the winner!。以下程序中,文件test.txt已正确为“读”而打开,由文件指针fr指向该文件,则程序的输出结果是______。
main( )
{ FILE*fr;char str[40];
…
fgets(str,5,fr);
printf("%s/n",str);
fclose(fr);
}
[填空题]请补充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")) 【1】 (fp2
=fopen ("B. dat", "r") ) )
{
while ( (ch=fgetc (f
[填空题]请补充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=
[填空题]在C盘根目录下创建一个名为”c. txt”的文本文件,文本文件的内容从键盘读取,直到遇到"/n"(回车键)为止。程序清单如下:
#include<stdio.h>
#included<______>/*第一空*/
void main( )
{FILE *fp;
char c;
if((fp=fopen("C:/c.txt","______"))==NULL)/*第二空*/
{printf("can not open file!/n");exit(0);)
while((______)!==’/n’)/*第三空*/
fput(c,fp);
fclose(fp);
}
[填空题]在当前目录下有一个名为myfile.txt的文本文件,其中有若干行文本。下面程序的功能是读入此文件中的所有文本行,按行计算每行字符的ASCII码之和,并显示在窗体上。请填空。
Private Sub Command1_Click( )
Dim ch$, ascii As Integer
Open "myfile.txt" For (11) As #1
While Not EOF(1)
Line Input #1, ch
ascii=toascii( (12) )
Print ascii
Wend
Close #1
End Sub
Private Function toascii(myStr$) As Integer
n=0
For k=1 To (13)
n=n+Asc(Mid(myStr,k,1))
Next k
toascii=n
End Function
[简答题]【说明】
编写程序,生成一个新文本文件,它由一个已知文本文件的所有偶数行组成。要求已知文本文件名和新文本文件名均从键盘输入。请填空完善程序。
【C语言程序】
#include<stdio.h>
main( )
{
FILE *oldf,*newf;
char ch,fname[20];
int i;
do{
printf("Enter name of existed text file to be read:");
scanf("%s",fname);
if((oldf=fopen(fname,"r"))==NULL)
printf("File %s can’t open!/n",fname);
}while(oldf==NULL);
do{
printf("Enter mane of new text file to be written:");
scanf("%s",fname);
if(( (1) ==NULL)
printf("File %s can’t open!/n",fname);
}while( (2) );
i=1;
while(!feof(oldf))
{
while((ch=fgetc(oldf))!= (3) )
{
if(i%2== (4) )
fputc(ch,newf);
}
fputc(’/n’,newf);
(5) ;
}
fclose(oldf);
fclose(newf);
}
[多项选择]【说明】
编写程序,生成一个新文本文件,它由一个已知文本文件的所有偶数行组成。要求已知文本文件名和新文本文件名均从键盘输入。请填空完善程序。
【C语言程序】
#include<stdio.h>
main( )
FILE *oldf,*newf;
char ch,fname[20];
int i;
do
printf("Enter name of existed text file to be read:");
scanf("%s",fname);
if((oldf=fopen(fname,"r"))==NULL)
printf("File %s can’t open!/n",fname);
while(oldf==NULL);
do
printf("Enter mane of new text file to be written:");
scanf("%s",fname);
if(( (1) ==NULL)
printf("File %s can’t open!/n",fname);
while( (2) );
i=1;
while(!feof(oldf))
while((ch=fgetc(oldf))!= (3) )
if(i%2== (4) )
fputc(ch,newf);
fputc(’/n’,newf);
(5) ;
fclose(oldf);
fclose(newf);