#include <stdio.h>
typedef struct
{
int total_chars;
int upper_case;
int lower_case;
int digits;
int spaces;
int non_alnum;
int vowels;
int non_vowels;
int special_chars;
char special_printables[ 128 ] ;
int hex_digits;
int octal_digits;
int binary_digits;
} stringStats;
// **********************************************************************************************
// Function: blackJackValue
//
// Description: gets the value of 2 given cards
//
// Parameters: card1 - char of a card, from 2-9, T, K, Q, J for 10, and A for 11
// card2 - same values as card1
//
// Returns: total - int value of both cards, unless 2 A values, in which the total will be 12,
// returns -1 if invalid input
//
// **********************************************************************************************
stringStats getStringStats( const char * str)
{
stringStats result = { 0 } ; //set everything to 0
int specialIndex = 0 ;
for ( int i = 0 ; str[ i] != '\0 ' ; i++ )
{
//all credit goes to the C standard library for making this section much easier
char ch = str[ i] ;
result.total_chars ++;
if ( isupper ( ch
) ) result.
upper_case ++; if ( islower ( ch
) ) result.
lower_case ++; {
result.non_alnum ++;
{
result.special_chars ++;
result.special_printables [ specialIndex++ ] = ch;
}
} //checks if a number is not alphanumeric, then if its printable or a space, if not, then increments the amount of special chars, and adds the char to the special printables
if ( strchr ( "AEIOUaeiou" , ch
) ) result.
vowels ++; //finally caved and used a better way of finding specific chars else if ( isalpha ( ch
) ) result.
non_vowels ++; if ( ( ch
>= '0' && ch
<= '9' ) || ( toupper ( ch
) >= 'A' && toupper ( ch
) <= 'F' ) ) result.
hex_digits ++; if ( ch >= '0' && ch <= '7' ) result.octal_digits ++;
if ( ch == '0' || ch == '1' ) result.binary_digits ++; //checks for hex, octal, and binary
}
return result;
}
int main( ) {
const char * testStr = "Hello World! 123 ABC @#$%@#$% 0xF7" ;
stringStats stats = getStringStats( testStr) ;
printf ( "Total characters: %d\n " , stats.
total_chars ) ; printf ( "Uppercase characters: %d\n " , stats.
upper_case ) ; printf ( "Lowercase characters: %d\n " , stats.
lower_case ) ; printf ( "Digits: %d\n " , stats.
digits ) ; printf ( "Spaces: %d\n " , stats.
spaces ) ; printf ( "Non-alphanumeric characters: %d\n " , stats.
non_alnum ) ; printf ( "Vowels: %d\n " , stats.
vowels ) ; printf ( "Non-vowels: %d\n " , stats.
non_vowels ) ; printf ( "Special characters: %d\n " , stats.
special_chars ) ; printf ( "Special printable characters: %s\n " , stats.
special_printables ) ; printf ( "Hexadecimal digits: %d\n " , stats.
hex_digits ) ; printf ( "Octal digits: %d\n " , stats.
octal_digits ) ; printf ( "Binary digits: %d\n " , stats.
binary_digits ) ;
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp0eXBlZGVmIHN0cnVjdCAKewogICAgaW50IHRvdGFsX2NoYXJzOwogICAgaW50IHVwcGVyX2Nhc2U7CiAgICBpbnQgbG93ZXJfY2FzZTsKICAgIGludCBkaWdpdHM7CiAgICBpbnQgc3BhY2VzOwogICAgaW50IG5vbl9hbG51bTsKICAgIGludCB2b3dlbHM7CiAgICBpbnQgbm9uX3Zvd2VsczsKICAgIGludCBzcGVjaWFsX2NoYXJzOwogICAgY2hhciBzcGVjaWFsX3ByaW50YWJsZXNbMTI4XTsKICAgIGludCBoZXhfZGlnaXRzOwogICAgaW50IG9jdGFsX2RpZ2l0czsKICAgIGludCBiaW5hcnlfZGlnaXRzOwp9IHN0cmluZ1N0YXRzOwoKLy8gKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgovLyBGdW5jdGlvbjogYmxhY2tKYWNrVmFsdWUKLy8KLy8gRGVzY3JpcHRpb246IGdldHMgdGhlIHZhbHVlIG9mIDIgZ2l2ZW4gY2FyZHMKLy8KLy8gUGFyYW1ldGVyczogY2FyZDEgLSBjaGFyIG9mIGEgY2FyZCwgZnJvbSAyLTksIFQsIEssIFEsIEogZm9yIDEwLCBhbmQgQSBmb3IgMTEKLy8JCQkgICBjYXJkMiAtIHNhbWUgdmFsdWVzIGFzIGNhcmQxCi8vCi8vIFJldHVybnM6ICAgIHRvdGFsIC0gaW50IHZhbHVlIG9mIGJvdGggY2FyZHMsIHVubGVzcyAyIEEgdmFsdWVzLCBpbiB3aGljaCB0aGUgdG90YWwgd2lsbCBiZSAxMiwKLy8JCQkgICByZXR1cm5zIC0xIGlmIGludmFsaWQgaW5wdXQKLy8KLy8gKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpzdHJpbmdTdGF0cyBnZXRTdHJpbmdTdGF0cyhjb25zdCBjaGFyICpzdHIpIAp7CiAgICBzdHJpbmdTdGF0cyByZXN1bHQgPSB7MH07IC8vc2V0IGV2ZXJ5dGhpbmcgdG8gMAogICAgaW50IHNwZWNpYWxJbmRleCA9IDA7CgogICAgZm9yIChpbnQgaSA9IDA7IHN0cltpXSAhPSAnXDAnOyBpKyspIAogICAgewogICAgCS8vYWxsIGNyZWRpdCBnb2VzIHRvIHRoZSBDIHN0YW5kYXJkIGxpYnJhcnkgZm9yIG1ha2luZyB0aGlzIHNlY3Rpb24gbXVjaCBlYXNpZXIKICAgICAgICBjaGFyIGNoID0gc3RyW2ldOwogICAgICAgIHJlc3VsdC50b3RhbF9jaGFycysrOwogICAgICAgIGlmIChpc3VwcGVyKGNoKSkgcmVzdWx0LnVwcGVyX2Nhc2UrKzsKICAgICAgICBpZiAoaXNsb3dlcihjaCkpIHJlc3VsdC5sb3dlcl9jYXNlKys7CiAgICAgICAgaWYgKGlzZGlnaXQoY2gpKSByZXN1bHQuZGlnaXRzKys7CiAgICAgICAgaWYgKGlzc3BhY2UoY2gpKSByZXN1bHQuc3BhY2VzKys7CiAgICAgICAgaWYgKCFpc2FsbnVtKGNoKSkKICAgICAgICB7CiAgICAgICAgICAgIHJlc3VsdC5ub25fYWxudW0rKzsKICAgICAgICAgICAgaWYgKGlzcHJpbnQoY2gpICYmICFpc3NwYWNlKGNoKSkgCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHJlc3VsdC5zcGVjaWFsX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