## The challenge

You will be given a string and your task will be to return a list of ints detailing the count of uppercase letters, lowercase, numbers and special characters, as follows.

 ``````1 2 `````` ``````Solve("*'&ABCDabcde12345") = [4,5,5,3]. --the order is: uppercase letters, lowercase, numbers and special characters. ``````

## The solution in C

Option 1:

 `````` 1 2 3 4 5 6 7 8 9 10 `````` ``````void count_char_types (const char *string, unsigned counts) { char c; counts = counts = counts = counts = 0; while((c = *string++)) if(c >= 'A' && c <= 'Z') counts++; else if(c >= 'a' && c <= 'z') counts++; else if(c >= '0' && c <= '9') counts++; else counts++; } ``````

Option 2:

 `````` 1 2 3 4 5 6 7 8 9 10 11 12 `````` ``````#include void count_char_types (const char *string, unsigned counts) { counts = counts = counts = counts = 0; for(const char* p = string; *p; p++){ if(isupper(*p)) counts++; else if(islower(*p)) counts++; else if(isdigit(*p)) counts++; else counts++; } } ``````

Option 3:

 `````` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 `````` ``````#include #include void count_char_types (const char *string, unsigned counts) { memset(counts, 0, 4 * sizeof(unsigned)); char c; while((c = *string++)){ if (isupper(c)) ++counts; else if (islower(c)) ++counts; else if (isdigit(c)) ++counts; else ++counts; } } ``````

## Test cases to validate our solution

 `````` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 `````` ``````#include extern void do_test (const char *string, const unsigned expected); #define ARRAY (const unsigned) Test(tests_suite, sample_tests) { do_test("bgA5<1d-tOwUZTS8yQ", ARRAY {7, 6, 3, 2}); do_test("P*K4%>mQUDaG\$h=cx2?.Czt7!Zn16p@5H", ARRAY {9, 9, 6, 9}); do_test("RYT'>s&gO-.CM9AKeH?,5317tWGpS<*x2ukXZD", ARRAY {15, 8, 6, 9}); do_test("\$Cnl)Sr<7bBW-&qLHI!mY41ODe", ARRAY {10, 7, 3, 6}); do_test("@mw>0=QD-iAx!rp9TaG?o&M%l\$34L.nbft", ARRAY {7, 13, 4, 10}); do_test("", ARRAY {0, 0, 0, 0}); } ``````