更多"编写一个函数findStr( ),该函数统计一个长度为2的字符串在另一"的相关试题:
[简答题]编写一个函数findStr( ),该函数统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为"asd asasdfg asd as zx67 asd mklo",子字符串为“as”,函数返回值是6。
函数ReadWrite( )的功能是实现从文件in40.dat中读取两个字符串,并调用函数findstr( ),最后把结果输出到文件out40.dat中。
注意:部分源程序已给出。
请勿改动主函数main( )和其他函数中的任何内容,仅在函数findStr( )的花括号中填入你所编写的若干语句。
#include<stdio.h>
#include<string.h>
#include<conio.h>
int findStr(char *str,char *substr)
main ( )
char str[81],substr[3];
int n;
clrscr( );
printf("输入原字符串: ");
gets(str);
printf ("输入子字符串: ");
gets(substr);
puts(str);
puts(substr);
n=findStr(str,substr);
printf("n=%dkn",n);
ReadWrite( );
ReadWrite( )
char ch, str[81],substr[3];
int n,len, i=0;
FILE *rf,*wf;
rf=fopen("in40.dat","r");
wf=fopen("out40.dat","w");
[简答题]编写一个函数findStr( ),该函数统计一个长度为2的子字符串在另一个字符串中出现的次数。例如,假定输入的字符串为"asd asasdfg asd as zx67 asd mklo",子字符串为"as",函数返回值是6。
函数ReadWrite( )实现从文件in.dat中读取两个字符串并调用函数findStr( ),最后把结果输出到文件out.dat中。
注意:部分程序已经给出。
请勿改动主函数main( )和其他函数中的任何内容,仅在函数findStr( )的花括号中填入你编写的若干语句。
#include <stdio.h>
#include <string.h>
#include <conio.h>
int findStr(char *str,char *substr)
main( )
char str[81],substr[3];
int n;
clrscr( );
printf("输入原字符串");
gets(str) ;
printf("输入子字符串:");
gets(substr);
puts(str);
puts(substr);
n=findStr(str, substr);
printf("n=%d/n", n);
ReadWrite( );
ReadWrite( )
char str[81],substr[3],ch;
int n, len,i=0;
FILE *rf, *wf;
rf=fopen("in.dat", "r");
wf=fopen("out.dat", "w");
while(i<25)
fgets(str, 80, rf);
fgets(substr, 10, rf);
len=strlen(substr)-1;
ch=substr[l
[简答题]编写函数findStr( ),该函数统计一个长度为2的子字符串在另一个字符串中出现的次数。例如,假定输入的字符串为”asd asasdfg asd as zx67 asd mklo”,子字符串为”as”,函数返回值为6。
函数ReadWrite( )实现从in.dat文件中读取两个字符串,并调用函数findStr( ),最后,把结果输出到out.dat文件中。
注意:部分程序已经给出。
请勿改动主函数main( )和其他函数中的任何内容,仅在函数findStr( )的花括号中填入你编写的若干语句。
#include<Stdio.h>
#include<string.h>
#include<conio.h>
int findStr(char*Str,char*substr)
void ReadWrite( )
char str[81],substr[10],ch;
int n,len,i=0;
FILE *rf,*wf;
rf=fopen("in.dat","r");
wf=fopen("out.dat","w");
while(i<25)
fgets(Str,81,rf);
fgets(substr,10,rf);
len=Strlen(substr)-1;
ch=substr[len];
if(ch==’/n’|| ch==0xla)
substr[len]=0;
n=findStr(Str,substr);
fprintf(wf,"%d/n",n);
i++;
fclose(rf);
fclose(wf);
main( )
char Str[81],substr[10];
int n;
printf("输入原字符串:");
gets(str);
printf("输入子字符串:");
gets(substr);
puts(str);
puts(su
[简答题]编写一个函数findStr( ),该函数的功能是:统计一个以单词组成的字符串中(各单词之间以空格隔开)所含指定长度单词的个数。例如,输入字符串为"you are very good you",指定要查找的单词的长度为3,则函数返回值是3。
函数readWriteData( )的功能是从IN.DAT中读取字符串和子字符串,并把统计结果输出到屏幕和文件OUT.DAT中。
注意:部分源程序已给出。
请勿改动主函数main( )和函数WriteData(int n)中的内容。
试题程序:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void readWriteData( );
int findStr(char*str,int find_len)
void main( )
char str[81];
int find_len;
int n;
system("CLS");
printf("input the strings:");
gets(str);
printf("input the length:");
seanf("%d",&find_len);
puts(str);
printf("length=%d",find_len);
n=findStr(str,find_len);
printf("n=%d",n);
readWriteData( );
void readWriteData( )
char str[81],substr[11];
int n,len,i=0;
FILE*rf,*wf;
rf=fopen("IN.DAT","r");
wf=fopen("OUT.DAT","W");
while(i<3)
fgets(str,80,rf);
fgets(substr,10,rf)
[简答题]编写一个函数,该函数可以统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为asd asasdfg asd as zx67 asd mklo,子字符串为as,则应当输出6。
注意:部分源程序给出如下。
请勿改动主函数main和具他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
int fun(char *str, char *substr)
main ( )
char str[81],substr[3];
int n;
clrscr ( );
printf ("输入主字符串 ");
gets (str);
printf ("输入子字符串");
gets (substr);
puts (str);
puts (substr);
n=fun (shr, substr);
printf("n=%d/n ",n);
[简答题]编写一个函数,用该函数可以统计一个长度为3的字符串在另一个字符串中出现的次数。例如,假定输入字符串“the abcthe they have theren”,子字符串为“the”,则应输出4。
注意:部分源程序在文件PROC2.CPP中。
请勿改动主函数和其他函数中的任何内容,仅在fun( )的花括号中填入编写的若干语句。
部分源程序如下:
//PROC2.CPP
#include <iostream>
using namespace std;
#define MAX 100
int fun(char *str,char *substr);
int main( ){
char str[MAX],substr[3];
int n;
cout<<"Please Input the source String/n";
cin>>str;
cout<<"Please Input the subString/n";
cin>>substr;
n=fun(str, substr);
cout<<"The counter is: "<<n<<end1;
return 0;
}
int fun(char *str,char *substr)
{
//******
}
[简答题]编写一个函数find Str( ),该函数统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为"asd asasdfg asd as zx67 asd mklo",子字符串为“as”,函数返回值是6。
函数ReadWrite( )的功能是实现从文件in40.dat中读取两个字符串,并调用函数findStr( ),最后把结果输出到文件out40.dat中。
注意:部分源程序已给出。
请勿改动主函数main( )和其他函数中的任何内容,仅在函数findStr( )的花括号中填入你所编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
int findStr(char *str,char *substr)
main( )
char str[81],substr[3];
int n;
clrscr( );
printf ("输入原字符串:");
gets(str);
printf("输入子字符串:");
gets(substr);
puts(str);
puts(substr);
n=findstr(str,substr);
printf("n=%d/n",n);
ReadWrite( );
ReadWrite( )
char ch,str[81],substr[3];
int n, len, i=0;
FILE *rf,*wf;
rf=fopen ("in40.dat","r");
wf=fopen ("out40.dar","w");
while (i<5)
fgets(str,80,rf);
fgets(substr,10,rf);
le
[填空题]请补充函数fun( ),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为: asd ascasdfg asd as asd mlosd,子字符串为asd,则应输出4。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
int fun(char *str,char *substr)
int n;
char *p,*r;
【1】 ;
while(*str)
p=str;
r=substr;
while(*r)
if( 【2】 )
r++;
p++;
else
break;
if( 【3】 )
n++;
str++;
return n;
main( )
char str[81],substr[3];
int n;
clrscr( );
printf("输入主字符串: ");
gets(str);
printf("输入子字符串:");
gets(substr);
puts(str);
puts(substr);
n=fun(str,substr);
printf("n=%d/n",n);
[简答题]请编写一个函数int stringLen(char*ps),该函数能计算出字符串ps的长度,函数返回值就是字符串的长度(不包括字符串结束标识号’/0’)。本题要求:用指针方式及循环来实现该函数。
注意;部分源程序已存在考生文件夹下的文件PROC6,cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数stringLen( )的花括号中填写若干语句。
文件PROC6.cpp的内容如下:
//PROC6.cpp
#include<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)
// * * * * *
[简答题]请编写一个函数fun( ),其功能是比较两个字符串的长度(不得调用C语言提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。
例如,输入beijing<CR>shanghai<CR>(<CR>为回车键),函数将返回shanghai。
#include<stdio.h>
char*fun(char*s,char*t)
main( )
char a[20],b[20];
void NONO( );
printf("Input 1th string:");
gets(a);
printf("Input 2th string:");
gets(b);
printf("%s/n",fun(a,b));