Coursework for the Master's course Computational Data Science: Advanced Programming
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

49 lines
1.1 KiB

#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 >= 'A' && *ptr <= 'Z' )
{
++chars_capital;
}
else if ( *ptr >= 'a' && *ptr <= 'z' )
{
++chars_lower;
}
else if ( *ptr >= '0' && *ptr <= '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 ;
}