0
コード実行時にキーボードから値を入力する際に問題があります。すべてが正常にコンパイルが、私は自分のコードを実行するために行くとき、それは次のように出力します:印刷機能で最初の値を入力できない
How many numbers would you like to place in the array: 7
Enter number 1: Enter number 2:
など、など
ですが、なぜでしょうか?また、各要素が配列内にある回数を数えて格納する方法はありますか?
int j = 0;
char numStorage[j];
で
int main(void)
{
int numbers = 0;
int j = 0;
char numStorage[j];
int times = 0;
char newArray[j];
printf("How many numbers would you like to place in the array: ");
scanf("%d", &numbers);
j = numbers;
int i = 1;
while (i < (numbers + 1))
{
printf("Enter number %d: ", i);
scanf("%c", &numStorage[i]);
i++;
}//close of while loop
int x;
for (x = 0; x < numbers; x++)
{
newArray[x] = numStorage[x];
}//close of for loop
int z;
int q;
for (z = 0; z < numbers; z++)
{
for (q = 0; q < numbers; q++)
{
if (numStorage[z] == numStorage[q])
{
times++;
q++;
}//close of if
else
{
q++;
}//close of else
}//close of for loop
printf("\n%d occurs %d times", numStorage[z], times);
z++;
q = 0;
times = 0;
}//close of for loop
}//end of main method
これも問題ですが、主な問題は、改行が数字の後ろに残っているため、入力を待たずに最初の '"%c "'が改行を取得することです。 –
@JonathanLefflerよろしくお願いします。私はその点を見落とした.. – sjsam