New Folder Structure because of mail 2019-11-21T16:35
This commit is contained in:
parent
890f414d86
commit
d1547c1611
21 changed files with 0 additions and 0 deletions
49
ex1.2/string_analyzer.cpp
Normal file
49
ex1.2/string_analyzer.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <iostream>
|
||||
using namespace std ;
|
||||
|
||||
#define MAX_STR_LENGTH 50
|
||||
|
||||
int main() {
|
||||
|
||||
char str[MAX_STR_LENGTH];
|
||||
// set pointer to beginning of str
|
||||
char* ptr = &str[0];
|
||||
|
||||
// get string from user
|
||||
std::cout << "Enter string (N < " << MAX_STR_LENGTH << ") :";
|
||||
std::cin.getline (str, MAX_STR_LENGTH);
|
||||
std::cout << std::endl;
|
||||
|
||||
// loop while the pointer does not point to a null byte
|
||||
// move the pointer one position at the end of the loop
|
||||
unsigned int chars_capital = 0, chars_lower = 0, chars_digits = 0, chars_other = 0;
|
||||
while ( *ptr != 0 )
|
||||
{
|
||||
if ( *ptr >= int('A') && *ptr <= int('Z') )
|
||||
{
|
||||
++chars_capital;
|
||||
}
|
||||
else if ( *ptr >= int('a') && *ptr <= int('z') )
|
||||
{
|
||||
++chars_lower;
|
||||
}
|
||||
else if ( *ptr >= int('0') && *ptr <= int('9') )
|
||||
{
|
||||
++chars_digits;
|
||||
}
|
||||
else
|
||||
{
|
||||
++chars_other;
|
||||
}
|
||||
|
||||
// move pointer one char further
|
||||
++ptr;
|
||||
}
|
||||
|
||||
std::cout << chars_capital << " Uppercase" << std::endl;
|
||||
std::cout << chars_lower << " Lowercase" << std::endl;
|
||||
std::cout << chars_digits << " Digits" << std::endl;
|
||||
std::cout << chars_other << " Other" << std::endl;
|
||||
|
||||
return 0 ;
|
||||
}
|
Reference in a new issue