更多"从键盘输入一串字符(“*”作为结束标志),将其写入文本文件file.d"的相关试题:
[填空题]从键盘输入一串字符("#"作为结束标志),将其写入文本文件file.dat中保存。
#include<stdio.h>
#include<stdlih.h>
main( )
char ch;
FILE*fp:
if((fp=fopen("file.det","______"))==NULL)/*第一空*/
printf("Can not open file/n");exit(0);
ch=getchar( );
whil(ch!’#’)
fputc(______,fp);/*第二空*/
ch=getchar( );
fclose(______); /*第三空*/
[填空题]从键盘输入一串字符("#"作为结束标志),将其写入文本文件file.dat中保存。
#include<stdio.h>
#include<stdlih.h>
main( )
{char ch;
FILE*fp:
if((fp=fopen("file.det","______"))==NULL)/*第一空*/
{printf("Can not open file/n");exit(0);}
ch=getchar( );
whil(ch!’#’)
{fputc(______,fp);/*第二空*/
ch=getchar( );
}
fclose(______); /*第三空*/
}
[填空题]
键入一串字符(换行作为结束标志),统计字符的个数,将该串字符及字符个数显示到屏幕上并写入文件str.dat中。
#include<stdio.h>
main( ) {
char ch;int sumch=0;
FILE*fp;
fp=fopen ("str.dat","w");
while((ch=getchar( ))!=______)/*第一空*/ {
sumch++; putchar(ch);
fputc(______,fp);/*第二空*/
}
printf("sumch=%d/n",sumch);
fprintf(______,"sumch=%d/n",sumch);/*第三空*/
fclose(fp);
}
[填空题]以下程序中用户由键盘输入一个文件名,然后输入一串字符(用#结束输入)存放到此文件中,形成文本文件,并将字符的个数写到文件的尾部。请填空。
#include<stdio.h>
main( )
{ FILE *fp;
char ch,fname[32]; int count=0;
printf(”Input the filename:");
scanf("%s",fname);
if((fp=fopen( 【12】 ,"w+"))==NULL)
{ printf("Can’t open file:%s/n",fname);exit(0);}
printf("Enter data:/n");
while((ch=getchar( ))!=’#’)
{ fputc(ch,fp);count++;}
fprintf( 【13】 ,"/n%d/n",count);
fclose(fp);
}
[填空题]下列程序的功能是通过函数func输入字符并统计输入字符的个数。输入时用字符@作为输入结束标志,请填空。
#include<stdio.h>
long______;/*函数说明语句*/
main( )
long n;
n=func( );printf("n=%1d/n",n);
long func( )
long m;
for(m=0;getchar( )!=’@’;______);
return m;
[填空题]将字符串写入文件时,不写入文件的字符串结束标志是______。
[填空题]以下程序的功能是:通过函数func输入字符并统计输入字符的个数。输入时用字符@作为输入结束标志。请填空。
#include <stdio.h>
long 【14】 ; /*函数说明语句*/
main( )
{ long n;
n=func( ); printf("n=%1d/n"n);
}
long func( )
{ long m;
for( m=0;getchar( )!=@ 【15】 ;
return m;
}
[填空题]字符型常量也称为字符串,它是由字符串"定界符"括起来的一串字符,定界符可以是单引号、双引号或()