Я должен посчитать количество букв верхнего и нижнего регистра в данной строке.Для этого назначения я должен использовать массивы символов, оканчивающиеся на \ 0, что я и делаю.Я использую код ascii для определения строчных или прописных букв.Тем не менее, результат иногда чистый, иногда не чистый.Любая помощь будет оценена.Вот мой код в Dev-C ++.Спасибо
#include <iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int getline();
int isupper(char line[]);
int islower(char line[]);
int main()
{
int Month, last_digit; //initialize variables and char array
char temp[255];
getline();
getch();
return 0;
}
int getline()
{
char line[255];
cout << "Enter a sentence: ";
cin.getline (line, 255);
isupper(line);
islower(line);
getch();
return 0;
}
int isupper(char line[])
{
int y, i=0, k=0; int count_uppercase=0; char Uppercase_array[80];
cout<<endl<<"from isupper function"<<endl;
do
{
y=line[i++]; // Convert to int
if(y>64 && y<91) //if it is a Uppercase letter...
{
Uppercase_array[k]=line[i-1];
k++;
count_uppercase++; //increment the counter...
}
}
while(y);
cout<<"Uppercase letter = " <<Uppercase_array;
cout<<" number of uppercase = "<<count_uppercase<<endl;
cout<<"----------"<<endl;
return 0;
}
int islower(char line[])
{
int z, i=0, count_lowercase=0;
cout<<"from lowercase function"<<endl;
do
{
z=line[i++]; // Convert to int
if(z>96 && z<123) //if it is a Lowercase letter...
count_lowercase++; ////increment the counter...
}
while(z);
cout<<"number of lowercase = "<<count_lowercase<<endl;
getch();
return 0;
}
*******example1 of output*****
Enter a sentence: Good morning Dad, how ARE u?
from isupper function
Uppercase found in that line = GDARE√" number of uppercase = 5
----------
from lowercase function
number of lowercase = 16
************example2 of output*********
Enter a sentence: Good morning Dad how are u?
from isupper function
Uppercase letter = GD number of uppercase = 2
----------
from lowercase function
number of lowercase = 19