//题目要求:编写一个程序,统计pstr所指字符串中所有非字母的个数,并去除这些非字母字符,然后将剩余字符进行大小写互换并输出。
//如char *pstr=“&vIS4ION,wa6re”,则非字母个数为4,输出为“VisionWARE” 。
#include<iostream>
using namespace std;
#define MAX 100
void print_Result(int, char arry[], int j);//函数声明
void My_string(char *str)
{
char*p = str;
int count = 0;
int i = 0,j=0;
char arry[MAX];//不能用int
while (*p != '\0')
{
if (*p >= 'a'&&*p <= 'z' || *p >= 'A'&&*p <= 'Z')
{
if (*p >= 'a'&&*p <= 'z')//小写
{
arry[j++] = *p - 'a' + 'A';
}
if (*p >= 'A'&&*p <= 'Z')
{
arry[j++] = *p - 'A' + 'a';//大写
}
}
else
{
count++;
}
p++;
}
print_Result(count, arry, j);
}
void print_Result(int cnt, char arry[], int j)
{
int i;
for (i = 0; i < j; i++)
{
cout << arry[i];
}
cout << endl;
cout << "字符串中非字母的个数为:" << cnt << endl;
}
int main()
{
char *pstr = "&vIS4ION,wa6re";
My_string(pstr);
system("pause");
}
//题目要求:编写一个程序,统计pstr所指字符串中所有非字母的个数,并去除这些非字母字符,然后将剩余字符进行大小写互换并输出。 //如char *pstr=“&vIS4ION,wa6re”,则非字母
最新推荐文章于 2022-04-02 11:50:40 发布