0
私は入力の各単語の文字数を数え、ヒストグラムとして出力するC言語のプログラムを作っています。私は、このプログラムのループのための多くを使用しています、と私は彼らと、次のエラーを取得しています:私のforループで奇妙なエラーを得るC
これらのエラーを引き起こしている私のループで何letter_size_chart.c:35:37: error: expected expression
for (i = maximum; i >= MIN_CHARS; --i)
^
letter_size_chart.c:38:27: error: expected expression
for (j = MIN_CHARS; i <= MAX_CHARS; ++i)
^
letter_size_chart.c:48:23: error: expected expression
for (i = MIN_CHARS; i <= MAX_CHARS; i++)
^
letter_size_chart.c:50:23: error: expected expression
for (i = MIN_CHARS; i <= MAX_CHARS; i++)
^
4 errors generated.
?ここに私のコードは次のとおりです。あなたは空の文字列と#define
を行うと、
/*
sorts input by size of words into a histogram
*/
#define EOF -1
#define MAX_CHARS 10 /* max number of chars allowed in a word */
#define MIN_CHARS
#include<stdio.h>
#include<ctype.h>
int main()
{
int c, i, j, word_length, numbcountsize, maximum;
int numbcount[MAX_CHARS];
word_length = 0;
while ((c = getchar()) != EOF)
{
if (isalpha(c))
++word_length;
else
if (word_length != 0)
{
++numbcount[word_length - 1];
word_length = 0;
}
}
maximum = numbcount[0];
for (i = MIN_CHARS; i <= MAX_CHARS; i++)
if (numbcount[i - 1] > maximum)
maximum = numbcount[i];
for (i = maximum; i >= MIN_CHARS; --i)
{
printf("%d |", i);
for (j = MIN_CHARS; i <= MAX_CHARS; ++i)
{
if (j >= i)
printf(" * ");
else
printf(" ");
}
printf("\n");
}
printf(" | ");
for (i = MIN_CHARS; i <= MAX_CHARS; i++)
printf("_");
for (i = MIN_CHARS; i <= MAX_CHARS; i++)
printf("%d\n", i);
}
あなたは何として 'MIN_CHARS'を定義されていませんでした - あなたはの#define MIN_CHARS''後の番号が必要です。 –