更多"编写一个函数fun( ),它的功能是:实现两个字符串的连接(不使用库函"的相关试题:
[简答题]编写函数fun,其功能是:实现两个字符串的连接(不要使用库函数strcat),即把p2所指的字符串连接到p1所指的字符串的后面。
例如.分别输入下面两个字符串:
“FirstString--”
“SecondString”
程序输出:
“FirstString--SecondString”
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void fun(char p1[],char p2[])
int i,j;
for(i=0;p1[i]!=’/0’;i++);/*求出i为p1字符串的总长度,包括结束标记符*/
for(j=0;p2[j]!=’/0’;j++)
p1[i++]=p2[j];/*将p2字符串连在p1字符串后面*/
p1[i]=’/0’;/*在字符串最后加上结束标记符*/
void main( )
char s1[80],s2[40];
system("CLS"):
printf("Enter s1 and s2:/n");
scanf("%s%s",s1,s2);
printf("s1=%s/n",s1);
printf("s2=%s/n",s2);
printf("Invoke fun(s1,s2):n");
fun(s1,s2);
printf("After invoking:n");
printf("%s/n",s1);
[简答题]编写一个函数fun( ),它的功能是:实现两个字符串的连接(不使用库函数strcat),即把p2所指的字符串连接到p1所指的字符串后。
例如,分别输入下面两个字符串:
FirstString
SecondString
则程序输出:
FirstStringSecondString
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号小填入所编写的若干语句。
试题程序:
#include <stdio. h>
#include<conio. h>
void fun (char pi[],char p2[])
main ( )
char s1[80],s2[40];
clrscr ( );
printf("Enter s1 and s2:/n");
scanf ("%s%s", s1, s2);
printf ("s1=%s/n", s1);
printf("s2=%s/n",s2);
printf("Invoke fun(s1,s2) :/n");
fun(s1,s2);
printf("After invoking:/n");
printf ("%s/n", s1);
[简答题]请编写一个函数char *fun(char *s),其中s代表一个字符串。函数fun( )的功能是将字符串s的元素倒置。例如,输入为“teacher”,则应输出“rehcaet”。
注意:部分源程序已存在文件PROC10.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC10.cpp的内容如下:
//PROC10. cpp
#include <iostream>
#include <string>
using namespace std;
char *fun(char *s);
int main ( )
{
char str[81];
cout<<"Please enter a string:/n";
cin>>str;
cout<<"The result is:"<<fun(str));
cout<<end1;
return 0;
}
char*fun(char*s)
{
//* * * * * * * * *
}
[简答题]编写一个函数,该函数可以统计一个长度为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)
//******
[简答题]请编写一个函数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));
[简答题]请编写一个函数fun( ),该函数的功能是:返回给定字符串中大写字母字符的个数。
如字符串"Hello World"中,大写字母的个数为2个。
注意:部分源程序已存在文件PROC5.CPP中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC5.cpp的内容如下:
//PROC5.cpp
#include<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)
{
//**********
}
[简答题]请编写一个函数fun( ),该函数的功能是:返回给定字符串中大写字母字符的个数。
如字符串"Hello World"中,大写字母的个数为2个。
注意:部分源程序已存在文件PROC5.CPP中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC5.cpp的内容如下:
//PROC5.cpp
#include<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)
//**********
[填空题]C++中将两个字符串连接起来组成一个字符串的函数是______。
[简答题]编写一个函数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