Кажется, что программа может выглядеть следующим образом
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void)
{
enum { str_size = 22 };
char str[str_size];
puts( "\nCount total number of alphabets, digits and special characters");
puts( "--------------------------------------------------------------");
while ( 1 )
{
printf( "\nInput a string less than or equal to %d characters (Enter - exit): ",
str_size - 2 );
if ( fgets( str, str_size, stdin ) == NULL || str[0] == '\n' ) break;
unsigned int alpha = 0, digit = 0, special = 0;
// removing the appended new line character by fgets
str[ strcspn( str, "\n" ) ] = '\0';
for ( const char *p = str; *p != '\0'; ++p )
{
unsigned char c = *p;
if ( isalpha( c ) ) ++alpha;
else if ( isdigit( c ) ) ++digit;
else ++special;
}
printf( "\nThere are %u letters, %u digits and %u special characters in the string\n",
alpha, digit, special );
}
return 0;
}
Вывод программы может выглядеть следующим образом:
Count total number of alphabets, digits and special characters
--------------------------------------------------------------
Input a string less than or equal to 20 characters (Enter - exit): April, 22, 2020
There are 5 letters, 6 digits and 4 special characters in the string
Input a string less than or equal to 20 characters (Enter - exit):
Если пользователь просто нажмет клавишу Enter, l oop will fini sh.
Обратите внимание, что программа рассматривает пробелы и знаки пунктуации как специальные символы.