size_t CMyStr::_myStrlen(char const * srcStr)
{
size_t len = 0;
if (srcStr != NULL)
{
while (*(srcStr + len) != '\0')
{
len++;
}
}
return len;
} //字符串的最后为'\0'的问题,字符串的长度包括'\0'
//字符串之数字处理
CMyStr(int i)
{
int tempVal = i;
bool isFu = false;
if (tempVal < 0)
{
len = 2; // \0 -号
isFu = true;
tempVal = -tempVal;
}
else
len = 1; // \0
while (tempVal)
{
tempVal /= 10;
len++;
}
pStr = new char[len];
*(pStr + len - 1) = '\0';
if (ifFul)
{
tempVal = -i;
}
else
tempVal = i;
int index = 0;
while (tempVal)
{
int temp = tempVal % 10;
*(pStr + len - 2 - index) = temp + '0'; //转换为字符类型
tempVal /= 10;
index++;
}
if (isFu)
*pStr = '-';
}
//字母ASCII码 A--65 a--97
char *str;
int counter[26];
void doc::count()
{
for (int i = 0; i < length; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
counter[str[i] - 'a']++;
if (str[i] >= 'A' && str[i] <= 'Z')
counter[str[i] - 'A']++;
}
for (int index = 0; index < 26; ++index)
cout << (char)(index + 65) << " or " << (char)(index + 97) << " 出现的次数是:" << counter[index] << endl;
原文链接: https://www.cnblogs.com/ming-michelle/p/7629093.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/260865
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!