1
0
Fork 0
This repository has been archived on 2021-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
uni-m.cds-adv-prog/ex1/ex1.2/string_analyzer.cpp
Eric Teunis de Boone 4c31b5a287 Ex1: Copied Code from Intro CPP repo:
git@git.deboone.nl:ericteunis/documenten/uni/m.cpp.git
2019-11-12 10:49:02 +01:00

49 lines
1.1 KiB
C++

#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 ;
}