文档介绍:: .
r * str),该函数返回参数str所指向的字符串中具有最大
ASCII码的那个字符(如字符串"world"中字符'w'具有最大的ASCII码)。当str所指向的字符串为空时,则
返回空字符0x0或'\0'。
输出结果如下:
Good Morning!
Max char:r
注意:部分源程序已存在文件中。
请勿修改主函数main和其他函数中的任何内容,仅在函数MaxCharacter的花括号中填写若干语句。
文件的内容如下:
#include<>
#include<>
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 MaxCharacter (char *str)
{
可编辑可修改
if(str==NULL)
return 0x0;
char maxChar=0x0;
int len=strlen(str);
for(int i=0;i<len;i++)
{
if(str[i]>maxChar)
maxChar=str[i];
}
return maxChar;
}
字符串删除一
.简单应用题
编写函数fun(),该函数的功能是从字符串中删除指定的字符,同一字母的大、小写按不同字符处理。
例如:程序执行时输入字符串为turbo c and borland c++,从键盘上输入字符n,则输出后变为turbo
c ad borlad c++。
如果输入的字符在字符串中不存在,则字符串照原样输出。
注意:部分源程序已存在文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
文件的内容如下:
#include<>
#include<>
#include<>
void fun(char s[ ], int c)
{
}
void main()
{
static char str[ ]="turbo c and borland c++";
char ch;
cout<<"原始字符串:\n"<<str<<endl;
cout<<"输入一个字符:";
可编辑可修改
cin>>ch;
fun(str,ch);
cout<<"str="<<str<<endl;
}
【答案】
void fun(char s[ ], int c)
{
int i=0;
char *p;
p=s;
while(*p)