C++函数问题5

[复制链接]
查看11 | 回复0 | 2009-1-30 06:28:38 | 显示全部楼层 |阅读模式
编写函数max,其功能是将字符串s中最大字符的地址返回;再编写一个主函数,调用该函数,并将字符串s中从该最大字符开始的子串中的小写字母转换成大写字母,然后输出新的字符串s.例如s的内容为“qwertyui“,则从最大字符‘y\'开始的字串“yui”,处理后s为“qwertYUI”。函数形式为:char * max(char s[ ]) 希望详细点,谢谢。

                                                                                                #include <iostream>#include <assert.h>using namespace std;char * maxstr(char s[]) {        assert(s != NULL);        int len = strlen(s);        char *tmp = s;        int i,j;        char max = s[0];        for(i=1; i<len; i++)        {                if(max < s)                {                        max = s;                        j = i;                }        }        for(i=j; i<len; i++)        {                if(s >= \'a\' && s <= \'z\')                {                        s -= 32;                }        }        return tmp;}void main(){        char str[100];        cout<<"please input a string:";        cin>>str;        char *max = maxstr(str);        cout<<"转换后:"<<max<<endl;}                                       
提问者对答案的评价:
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行