有一篇文章,共有3行文字,每行有个80字符.要求分别统计出其中英文大写字母、小写字母、空格以及其它字符的个数。
#include
using namespace std;
int main()
{
char c[3][80], i = 0,j=0;
int letters = 0, space = 0, num = 0, other = 0, Capital = 0;
cout << "输入一段话:" << endl;
for (i = 0; i < 3; i++)
{
cin >> c[i][j]; //(1.感觉有问题,若为c[i]则无问题)
for (j = 0; j < 80 && c[i][j] != '\0'; j++)
{ //(2.可以在这里写输入吗,c[i][j],若不可为什么?)
if (c[i][j] >= 'a' && c[i][j] <= 'z')
letters++;
else if (c[i][j] >= 'A' && c[i][j] <= 'Z')
Capital++;
else if (c[i][j] == ' ')
space++;
else if (c[i][j] >= '0' && c[i][j] <= '9')
num++;
else
other++;
}
cout << "大写字母:" << Capital << "小写字母 " << letters << "空格:" << space << ", 数字:" << num << ", 其他:" << other << endl;
}
system("pause");
return 0;
}
问:1.
2.
3.输入时若输入的内容过多会数组越界的,有什么方法控制输入的使无论输多少都不会数组越界吗,不是改成动态形式的解决方式。xie'xie