Skip to main content
edited tags
Link
Toby Speight
  • 81.8k
  • 14
  • 101
  • 309
Tweeted twitter.com/StackCodeReview/status/1251571195998322690
Don't double-specify a pre block
Source Link
Reinderien
  • 65.6k
  • 5
  • 70
  • 191
    #include <stdio.h>
    #include <ctype.h>
    
    int main()
    {
        int ch, 
            nwhite, 
            nother;
    
        int num[10] = {0};
        int lett[26] = {0};

    nwhite = nother = 0;

    while ((ch = getchar()) != EOF)
    {
        if (isdigit(ch))
            ++num[ch-'0'];
        else if (isalpha(ch))
        {
            if(ch >='A' && ch <= 'Z')
                ch = tolower(ch);
                
            if(ch >= 'a' && ch <= 'k')
                ++lett[ch-'a'];
            else if(ch >= 'l' && ch <= 'v')
                ++lett[ch-'l'];
            else if(ch >= 'w' && ch <= 'z')
                ++lett[ch-'w'];
        }
            
        else if (ch == ' ' || ch == '\n' || ch == '\t')
            ++nwhite;
        else
            ++nother;
    }

    putchar('\n');

    printf("Numbers|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < num[i]; ++j)
            putchar('*');
    }
    putchar('\n');
    
    printf("Letters|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < lett[i]; ++j)
            putchar('*');
    }
    putchar('\n');

    printf("White spaces|");
    for(int i = 0; i <= nwhite; ++i)
    {
        if(nwhite - i > 0)
            putchar('*');
    }
    putchar ('\n');

    printf("Others|");
    for(int i = 0; i <= nother; ++i)
    {
        if(nother - i > 0)
            putchar('*');
    }
    putchar ('\n');
    
    return 0;
}
#include <stdio.h>
#include <ctype.h>
    
int main()
{
    int ch, 
        nwhite, 
        nother;

    int num[10] = {0};
    int lett[26] = {0};

    nwhite = nother = 0;

    while ((ch = getchar()) != EOF)
    {
        if (isdigit(ch))
            ++num[ch-'0'];
        else if (isalpha(ch))
        {
            if(ch >='A' && ch <= 'Z')
                ch = tolower(ch);
                
            if(ch >= 'a' && ch <= 'k')
                ++lett[ch-'a'];
            else if(ch >= 'l' && ch <= 'v')
                ++lett[ch-'l'];
            else if(ch >= 'w' && ch <= 'z')
                ++lett[ch-'w'];
        }
            
        else if (ch == ' ' || ch == '\n' || ch == '\t')
            ++nwhite;
        else
            ++nother;
    }

    putchar('\n');

    printf("Numbers|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < num[i]; ++j)
            putchar('*');
    }
    putchar('\n');
    
    printf("Letters|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < lett[i]; ++j)
            putchar('*');
    }
    putchar('\n');

    printf("White spaces|");
    for(int i = 0; i <= nwhite; ++i)
    {
        if(nwhite - i > 0)
            putchar('*');
    }
    putchar ('\n');

    printf("Others|");
    for(int i = 0; i <= nother; ++i)
    {
        if(nother - i > 0)
            putchar('*');
    }
    putchar ('\n');
    
    return 0;
}
    #include <stdio.h>
    #include <ctype.h>
    
    int main()
    {
        int ch, 
            nwhite, 
            nother;
    
        int num[10] = {0};
        int lett[26] = {0};

    nwhite = nother = 0;

    while ((ch = getchar()) != EOF)
    {
        if (isdigit(ch))
            ++num[ch-'0'];
        else if (isalpha(ch))
        {
            if(ch >='A' && ch <= 'Z')
                ch = tolower(ch);
                
            if(ch >= 'a' && ch <= 'k')
                ++lett[ch-'a'];
            else if(ch >= 'l' && ch <= 'v')
                ++lett[ch-'l'];
            else if(ch >= 'w' && ch <= 'z')
                ++lett[ch-'w'];
        }
            
        else if (ch == ' ' || ch == '\n' || ch == '\t')
            ++nwhite;
        else
            ++nother;
    }

    putchar('\n');

    printf("Numbers|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < num[i]; ++j)
            putchar('*');
    }
    putchar('\n');
    
    printf("Letters|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < lett[i]; ++j)
            putchar('*');
    }
    putchar('\n');

    printf("White spaces|");
    for(int i = 0; i <= nwhite; ++i)
    {
        if(nwhite - i > 0)
            putchar('*');
    }
    putchar ('\n');

    printf("Others|");
    for(int i = 0; i <= nother; ++i)
    {
        if(nother - i > 0)
            putchar('*');
    }
    putchar ('\n');
    
    return 0;
}
#include <stdio.h>
#include <ctype.h>
    
int main()
{
    int ch, 
        nwhite, 
        nother;

    int num[10] = {0};
    int lett[26] = {0};

    nwhite = nother = 0;

    while ((ch = getchar()) != EOF)
    {
        if (isdigit(ch))
            ++num[ch-'0'];
        else if (isalpha(ch))
        {
            if(ch >='A' && ch <= 'Z')
                ch = tolower(ch);
                
            if(ch >= 'a' && ch <= 'k')
                ++lett[ch-'a'];
            else if(ch >= 'l' && ch <= 'v')
                ++lett[ch-'l'];
            else if(ch >= 'w' && ch <= 'z')
                ++lett[ch-'w'];
        }
            
        else if (ch == ' ' || ch == '\n' || ch == '\t')
            ++nwhite;
        else
            ++nother;
    }

    putchar('\n');

    printf("Numbers|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < num[i]; ++j)
            putchar('*');
    }
    putchar('\n');
    
    printf("Letters|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < lett[i]; ++j)
            putchar('*');
    }
    putchar('\n');

    printf("White spaces|");
    for(int i = 0; i <= nwhite; ++i)
    {
        if(nwhite - i > 0)
            putchar('*');
    }
    putchar ('\n');

    printf("Others|");
    for(int i = 0; i <= nother; ++i)
    {
        if(nother - i > 0)
            putchar('*');
    }
    putchar ('\n');
    
    return 0;
}
#include <stdio.h>
#include <ctype.h>

int main()
{
    int ch, 
        nwhite, 
        nother;

    int num[10] = {0};
    int lett[26] = {0};

nwhite = nother = 0;

while ((ch = getchar()) != EOF)
{
    if (isdigit(ch))
        ++num[ch-'0'];
    else if (isalpha(ch))
    {
        if(ch >='A' && ch <= 'Z')
            ch = tolower(ch);
            
        if(ch >= 'a' && ch <= 'k')
            ++lett[ch-'a'];
        else if(ch >= 'l' && ch <= 'v')
            ++lett[ch-'l'];
        else if(ch >= 'w' && ch <= 'z')
            ++lett[ch-'w'];
    }
        
    else if (ch == ' ' || ch == '\n' || ch == '\t')
        ++nwhite;
    else
        ++nother;
}

putchar('\n');

printf("Numbers|");
for(int i = 0; i <= 10; ++i)
{
    for(int j = 0; j < num[i]; ++j)
        putchar('*');
}
putchar('\n');

printf("Letters|");
for(int i = 0; i <= 10; ++i)
{
    for(int j = 0; j < lett[i]; ++j)
        putchar('*');
}
putchar('\n');

printf("White spaces|");
for(int i = 0; i <= nwhite; ++i)
{
    if(nwhite - i > 0)
        putchar('*');
}
putchar ('\n');

printf("Others|");
for(int i = 0; i <= nother; ++i)
{
    if(nother - i > 0)
        putchar('*');
}
putchar ('\n');

return 0;

}

    #include <stdio.h>
    #include <ctype.h>
    
    int main()
    {
        int ch, 
            nwhite, 
            nother;
    
        int num[10] = {0};
        int lett[26] = {0};

    nwhite = nother = 0;

    while ((ch = getchar()) != EOF)
    {
        if (isdigit(ch))
            ++num[ch-'0'];
        else if (isalpha(ch))
        {
            if(ch >='A' && ch <= 'Z')
                ch = tolower(ch);
                
            if(ch >= 'a' && ch <= 'k')
                ++lett[ch-'a'];
            else if(ch >= 'l' && ch <= 'v')
                ++lett[ch-'l'];
            else if(ch >= 'w' && ch <= 'z')
                ++lett[ch-'w'];
        }
            
        else if (ch == ' ' || ch == '\n' || ch == '\t')
            ++nwhite;
        else
            ++nother;
    }

    putchar('\n');

    printf("Numbers|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < num[i]; ++j)
            putchar('*');
    }
    putchar('\n');
    
    printf("Letters|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < lett[i]; ++j)
            putchar('*');
    }
    putchar('\n');

    printf("White spaces|");
    for(int i = 0; i <= nwhite; ++i)
    {
        if(nwhite - i > 0)
            putchar('*');
    }
    putchar ('\n');

    printf("Others|");
    for(int i = 0; i <= nother; ++i)
    {
        if(nother - i > 0)
            putchar('*');
    }
    putchar ('\n');
    
    return 0;
}
#include <stdio.h>
#include <ctype.h>

int main()
{
    int ch, 
        nwhite, 
        nother;

    int num[10] = {0};
    int lett[26] = {0};

nwhite = nother = 0;

while ((ch = getchar()) != EOF)
{
    if (isdigit(ch))
        ++num[ch-'0'];
    else if (isalpha(ch))
    {
        if(ch >='A' && ch <= 'Z')
            ch = tolower(ch);
            
        if(ch >= 'a' && ch <= 'k')
            ++lett[ch-'a'];
        else if(ch >= 'l' && ch <= 'v')
            ++lett[ch-'l'];
        else if(ch >= 'w' && ch <= 'z')
            ++lett[ch-'w'];
    }
        
    else if (ch == ' ' || ch == '\n' || ch == '\t')
        ++nwhite;
    else
        ++nother;
}

putchar('\n');

printf("Numbers|");
for(int i = 0; i <= 10; ++i)
{
    for(int j = 0; j < num[i]; ++j)
        putchar('*');
}
putchar('\n');

printf("Letters|");
for(int i = 0; i <= 10; ++i)
{
    for(int j = 0; j < lett[i]; ++j)
        putchar('*');
}
putchar('\n');

printf("White spaces|");
for(int i = 0; i <= nwhite; ++i)
{
    if(nwhite - i > 0)
        putchar('*');
}
putchar ('\n');

printf("Others|");
for(int i = 0; i <= nother; ++i)
{
    if(nother - i > 0)
        putchar('*');
}
putchar ('\n');

return 0;

}

    #include <stdio.h>
    #include <ctype.h>
    
    int main()
    {
        int ch, 
            nwhite, 
            nother;
    
        int num[10] = {0};
        int lett[26] = {0};

    nwhite = nother = 0;

    while ((ch = getchar()) != EOF)
    {
        if (isdigit(ch))
            ++num[ch-'0'];
        else if (isalpha(ch))
        {
            if(ch >='A' && ch <= 'Z')
                ch = tolower(ch);
                
            if(ch >= 'a' && ch <= 'k')
                ++lett[ch-'a'];
            else if(ch >= 'l' && ch <= 'v')
                ++lett[ch-'l'];
            else if(ch >= 'w' && ch <= 'z')
                ++lett[ch-'w'];
        }
            
        else if (ch == ' ' || ch == '\n' || ch == '\t')
            ++nwhite;
        else
            ++nother;
    }

    putchar('\n');

    printf("Numbers|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < num[i]; ++j)
            putchar('*');
    }
    putchar('\n');
    
    printf("Letters|");
    for(int i = 0; i <= 10; ++i)
    {
        for(int j = 0; j < lett[i]; ++j)
            putchar('*');
    }
    putchar('\n');

    printf("White spaces|");
    for(int i = 0; i <= nwhite; ++i)
    {
        if(nwhite - i > 0)
            putchar('*');
    }
    putchar ('\n');

    printf("Others|");
    for(int i = 0; i <= nother; ++i)
    {
        if(nother - i > 0)
            putchar('*');
    }
    putchar ('\n');
    
    return 0;
}
Source Link
link23
  • 133
  • 1
  • 4
Loading