编写一个函数int charnum(char fn[10]),该函数以只读方式打开文件fn,通过统计,返回文件中字符的个数,请使用while循环实现计数功能。注意:部分源程序已存在文件test7_2.cpp中。请勿修改主函数main和其他函数中的任何内容,仅在函数charnum的花括号中填写若干语句。文件test7_2.cpp的内容如下:include<iostream.h>include<fstream.h>include<stdlib.h>int charnum(char fn[10]);void main(){int num;num=charnum("abc.txt");cout<<"num="<<num<<endl;}int charnum(char fn[10]){}

编写一个函数int charnum(char fn[10]),该函数以只读方式打开文件fn,通过统计,返回文件中字符的个数,请使用while循环实现计数功能。

注意:部分源程序已存在文件test7_2.cpp中。

请勿修改主函数main和其他函数中的任何内容,仅在函数charnum的花括号中填写若干语句。

文件test7_2.cpp的内容如下:

include<iostream.h>

include<fstream.h>

include<stdlib.h>

int charnum(char fn[10]);

void main()

{

int num;

num=charnum("abc.txt");

cout<<"num="<<num<<endl;

}

int charnum(char fn[10])

{

}


相关考题:

请编写一个函数int CalcDigital(char *str),该函数可返回字符串str中数字字符(即0~9这10个数字)的个数,如字符串“olympic2008”中数字字符的个数为4。请用if条件判断语句与for循环语句来实现该函数。注意:部分源程序已存在文件test9_2.cpp中。请勿修改主函数main和其他函数中的任何内容,仅在函数find的花括号中填写若干语句。文件test9_2.cpp的内容如下:include<iostream.h>include<string.h>int CalcDigital(char*str);void main(){char *str;str=new char[255];cout<<"输入字符串:";cin>>str;int num=CalcDigital(str);cout<<str<<":"<<num<<endl;}int CalcDigital(char *str){}

请编写一个函数int stringLen(char*ps),该函数能计算出字符串ps的长度,函数返回值就是字符串的长度(不包括字符串结束标识号'\0')。本题要求:用指针方式及循环来实现该函数。注意;部分源程序已存在考生文件夹下的文件PROC6,cpp中。请勿修改主函数和其他函数中的任何内容,仅在函数stringLen()的花括号中填写若干语句。文件PROC6.cpp的内容如下://PROC6.cppinclude<iostream>using namespace std;int stringLen(char *);int main(){char str[100],*p;cout<<"Input your string please!\n";cin>>str;p=str;cout<<"The lenth of your string is "<<stringLen(p)<<end1;return 0;}int stringLen(char *ps){// * * * * *}

有以下程序include void WriteStr(char*fn,char*str){FILE*fp; fp=fopen(fn,"w");fpu 有以下程序 #include <stdio.h> void WriteStr(char *fn, char *str) { FILE *fp; fp=fopen(fn,"w"); fputs(str,fp);fclose(fp); } main() { WriteStr("t1.dat","start"); WriteStr("t1.dat","end"); } 程序运行后,文件t1.dat中的内容是A.startB.endC.startendD.endrt

有以下程序:includevoid WriteStr(char *fn, char *sir){FILE * fP; fP=fopen(fn,"w") 有以下程序: #include<stdio.h> void WriteStr(char *fn, char *sir) { FILE * fP; fP=fopen(fn,"w"); fput6(str,fp); fclose(fp); } main() { WriteStr("t1.dar","start"); WrlteStr("t1.dat","end"); } 程序运行后,文件t1.dat中的内容是( )。A.startB.endC.startendD.endrt

请编写一个函数fun(),该函数的功能是:返回给定字符串中大写字母字符的个数。如字符串"Hello World"中,大写字母的个数为2个。注意:部分源程序已存在文件PROC5.CPP中。请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。文件PROC5.cpp的内容如下://PROC5.cppinclude<iostream>include<string>using namespace std;int fun(char *str);int main(){char str[ ]="Chinese Computer World";cout<<fun(str)<<end;return 0;}int fun(char *str){//**********}

请编写一个函数char MaxCharacmr(char *str),该函数返回参数str所指向的字符串中具有最大ASCII码的那个字符(如字符串“world”中字符‘w’具有最大的ASCII码)。当str所指向的字符串为空时,则返回空字符0x0或‘\0’。输出结果如下:Good Morning!Max char:r注意:部分源程序已存在文件test15_2.cpp中。请勿修改主函数main和其他函数中的任何内容,仅在函数MaxCharacter的花括号中填写若干语句。文件test15_2.cpp的内容如下:include<iostream.h>include<string.h>char MaxCharacter(char *str);void main(){char str[100];strcpy(str,"Good Morning!");char maxc=MaxCharacter(str);cout<<str<<endl;cout<<"Max char:"<<maxc<<endl;}char MaxCharacter(char*str){}

有以下程序includevoid WriteStr(char*fn,char*str){FILE*fp; fp=fopen(fn,"w");fputs 有以下程序 #include<stdio.h> void WriteStr(char*fn,char*str) { FILE*fp; fp=fopen(fn,"w");fputs(str,fp);fclose(fp); } main() { writeStr("t1.dat","start"); WriteStr("t1.dat","end"); } 程序运行后,文件t1.dat中的内容是A.startB.endC.startendD.endrt

有以下程序:includestdio.1lvoid WriteStr(char*fn.char*str){ FILE*fp;fp=fopen(fn,stdio.1lvoid WriteStr(char*fn.char*str){ FILE*fp;fp=fopen(fn,w);fputs(str,fp);fclose(fp);}main{ WriteStr(tl.dat,start);WriteStr(t1.dat,end);)程序运行后,文件t1.dat中的内容是( )。A. startB.endC.startendD.endrt

编写一个函数findStr(char*str,char*substr),该函数统计一个长度为2的子字符串substr在另一个字符串str中出现的次数,该次数作为函数值返回。例如,假定输入的字符串为”asd asasdfg asd as zx67 asdmklo”,子字符串为”as”,函数返回值是6。 函数ReadWrite实现从文件in.dat中读取两个字符串,并调用函数findStr,最后把结果输出到文件out.dat中。 注意:部分源程序存在test.c文件中。请勿改动主函数main和其他函数中的任何内容,仅在函数findStr的花括号中 填入你编写的若干语句。