简体   繁体   中英

C programming histogram

I'm getting an error on line number 8 that it needs an expected identifier '(' before a numeric constant, but I can't seem to fix it. Please help. This code is supposed to take each grade and create a histogram.

/* Histogram of Frequency of Different Characters in Input */

#include<stdio.h>
#define ch_grade 32  

int main(void)
{
char ch_grade [32] = {A, B, C, D, f, I, b, C, d, F, I, a, C, D, F, I, A, B, D, F, I, A, B, c, I, D, F, F, A, B, a, b};

int c,i,j;

int character[ch_grade];

for(i=0;i<ch_grade;++i)
    character[i] = 0;

while((c=getchar())!=EOF)
    ++character[c];

for(i=0;i<ch_grade;++i)
{
    putchar(i);

    for(j=0;j<character[i];++j)
        putchar('*');

    putchar('\n');
    }
return 0;
}

您需要将每个字符文字放在 ' ' 中,例如'A', 'B'等。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM