急用谢谢,用C++编写一个函数

来源:百度知道 编辑:UC知道 时间:2024/06/03 19:14:56
用C++编写一个函数,该函数返回给定字符串中大写字母字符的个数。例如:字符串“Chinese Computer World”中,大写字母字符的个数是3个。写出主函数,设计几个字符串,测试函数输出结果是否正确。函数首部参数要求用指向字符的指针,比如 int Fun(char *str)

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int Fun(char *str)
{
int number;
number = 0;
while ( *str != '\0' )
if ( isupper(*str++) )
number++;
return number;
}

void main()
{
const int N = 1000;
char str[N] = "null";
while (1)
{
printf("please input the test str or Exit to quit\n");
fgets(str,N,stdin);
if ( strncmp(str,"Exit",4) == 0 )
break ;
printf("Upper char is %d\n",Fun(str));
}
}

int funa( char *s ,int ik,)
{
char b;
b=mid(s,ik);
if b="/" return 0; //"/"是字符结束符

if b>= "A" and b<="z"
{
funa=funa(s,ik+1)+1;
return funa;
else
funa=funa(s,ik+1);
return funa;
}
}
main()
{
char str; //C++里是怎么定义字符串的啊?<