网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
请编写一个函数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)
{
}
参考答案
更多 “ 请编写一个函数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){} ” 相关考题
考题
以下函数 fun 的功能是返回 str 所指字符串中以形参 c 中字符开头的后续字符串的首地址 , 例如 : st r所指字符串为 : Hello! , c 中的字符为 e ,则函数返回字符串 : ello! 的首地址。若 str 所指字符串为空串或不包含 c 中的字符,则函数返回 NULL 。请填空。char *fun(char *str,char c){ int n=0; char *p=str;if(p!=NULL)while(p[n]!=cp[n]!='\0') n++;if(p[n]=='\0') return NULL;return( 【 1 2 】 );}
考题
●试题四请补充函数fun(),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为:asd ascasdfg asd as asd mlosd,子字符串为asd,则应输出4。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。试题程序:#includestdio.h#includestring.h#includeconio.hint fun(char *str,char *substr){int n;char *p,*r;(1) ;while(*str){p=str;r=substr;while(*r)if( (2) ){r++;p++;}elsebreak;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);}
考题
mystrlen函数的功能是计算str所指字符串的长度,并作为函数值返回。请填空。int mystrlen(char *str){ int i;for(i=0;【17】!= ′\0′;i++);return(i);}
考题
请编写一个函数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){}
考题
请补充函数fun,该函数的功能是比较字符串str1和str2的大小,井返回比较的结果。例如: 当str1=“cdef",str2=“cde”时,函数fun()返回“>”。注意:部分源程序给出如下。请勿改动主函数main 和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。试题程序:include< stdio, h>include<conio. h>define N 80char *fun (char *str1,char *str2){char *p1=str1, *p2=str2;while (*p1 *p2 ){if (【 】)return "<";if(【 】)return ">";p1++;p2++;}if (*p1=*p2)return "==";if (*p1==【 】)return "<";elsereturn ">";}main(){char str1 [N], str2 [N];clrscr ();printf ("Input str1: \n");gets (str1);printf ("Input str2: \n");gets (str2);printf ("\n*****the result*****\n");printf ("\nstr1 %s str2", fun (str1, str2) );}
考题
请补充函数fun(),该函数的功能是判断一个数是否为回文数。当字符串是回文时,函数返回字符申:yes!,否则函数返回字符串:no!,并在主函数中输出。所谓回文即正向与反向的拼写都一样,例如:abcba。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。试题程序:include<string.h>include<stdio.h>char *fun(char*str){char *p1,*p2;int i, t=0;p1=str;p2=str+strlen(str)-1;for (i=0;【 】;i++)if(【 】){t=1;break;}if (【 】)return("yes!");elsereturn("no!");}main(){char str[50];printf("Input;");scanf("%s",str);printf("%s\n",fun(str));}
考题
以下函数fun的功能是返回str所指字符串中以形参c中字符开头的后续字符串的首地址,例如,str所指字符串为Hello!,c中的字符为e,则函数返回字符串ello!的首地址。若str所指字符串为空或不包含c中的字符,则函数返回NULL,请填空。char *fun(char *str,char c){ int n=0; char *p=str; if(p!=NULL) while(p[n]!=cp[n]!=’\0’) n++; if(p[n]==’\0’) return NULL; return();}
考题
mystrlen函数的功能是计算str所指字符串的长度,并作为函数值返回,请填空。int mystrlen(char *str) { int i; for(i=0;;i++); return(i); }
考题
【判断题】函数返回值是指针类型的函数为指针函数,以下是一个指针函数的原型。 char *strcat(char *str1,char *str2)A.Y.是B.N.否
热门标签
最新试卷