注册 登录
编程论坛 C++教室

函数调用的不可以执行!

面朝大海1994 发布于 2013-05-08 09:20, 502 次点击
#include<iostream>
using namespace std;
int main()
{
    int letter=0,digit=0,space=0,other=0;   
    int i;
    char *p,string[20];
    void search(char *p,char string[]);

    cout<<"input string:"<<endl;
    while((string[i]=getchar())!='\n')
    i++;

    search(p,string);
    cout<<"letter="<<letter<<endl<<"space="<<space<<endl<<"digit="<<digit<<endl<<"other="<<other<<endl;
   
    return 0;
}
void search (char *p,char string[])
{
    int letter=0,digit=0,space=0,other=0;
      p=&string[0];
    while(*p!='\n')
    {
        if(('a'<=*p)&&(*p<='z')&&('A'<=*p)&&(*p<='z'))
           ++letter;
        else if(*p==' ')
            ++space;
        else if((*p<='9')&&(*p>='0'))

            ++digit;
        else
            ++other;
        p++;
    }

}
6 回复
#2
wp2319572013-05-08 09:21
函数调用的不可以执行!

这句话还真拗嘴  读不懂  中国国文博大精深
#3
rjsp2013-05-08 09:23
"函数调用的不可以执行!"  ------ 听不懂,有点像抗日片中鬼子的腔调^_^
#4
rjsp2013-05-08 09:35
程序代码:
#include <iostream>
#include <string>
using namespace std;

void search4( const char* str, size_t& letter, size_t& digit, size_t& space, size_t& other );

int main()
{
    cout << "input string:" << endl;
    string line;
    getline( cin, line );

    size_t letter, digit, space, other;
    search4( line.c_str(), letter, digit, space, other );

    cout << "letter = " << letter << '\n'
         << "space  = " << space  << '\n'
         << "digit  = " << digit  << '\n'
         << "other  = " << other  << endl;

    return 0;
}

void search4( const char* str, size_t& letter, size_t& digit, size_t& space, size_t& other )
{
    letter=0, digit=0, space=0, other=0;

    for( const char* p=str; *p; ++p )
    {
        char c = *p;

        if( (c>='A'&&c<='Z') || (c>='a'&&c<='z') )
            ++letter;
        else if( c>='0' && c<='9' )
            ++digit;
        else if( c == ' ' )
            ++space;
        else
            ++other;
    }
}
#5
面朝大海19942013-05-08 15:06
回复 3楼 rjsp
Thank you, may I say is too depression of the mouth
#6
面朝大海19942013-05-08 15:06
回复 2楼 wp231957
,Thank you
#7
面朝大海19942013-05-08 15:32
回复 4楼 rjsp
谢谢了,呵呵
1