関数に配列を送信しようとすると、エラーが発生します。配列を関数の引数として正しく渡すには?
これは私のminunitテストプログラムです:
#include "minunit.h"
#include "calc.h"
#include <stdio.h>
int tests_run = 0;
static char * test_Repetitve() {
mu_assert("error in test_Repetitive, Repetitive != 7", HistogramArray({1,2,3,4,5,6,7})== 7);
return 0;
}
static char * all_tests() {
mu_run_test(test_Repetitive);
return 0;
}
int main(int argc, char **argv) {
char *result = all_tests();
if (result != 0) {
printf("%s\n", result);
}
else {
printf("ALL TESTS PASSED\n");
}
printf("Tests run: %d\n", tests_run);
return result != 0;
}
mu_assert("error in test_Repetitive, Repetitive != 7", HistogramArray({1,2,3,4,5,6,7})== 7);
であり、それがこの機能に行くと、私は問題を抱えている行:基本的に
int HistogramArray(int one[])
{
int arrchk[TWENTY+ONE] = { ZERO }, i, j,counter=0;//arrchk is an array that counts how many times the number appears.
for (i = ZERO; i<N; i++)
arrchk[one[i]]++;
for (i = ZERO; i<TWENTY+ONE; i++)
{
if (arrchk[i] != ZERO)
{
printf("the number is %d ", i);//printing the histogram.
counter++;
}
for (j = ZERO; j<arrchk[i]; j++)
{
printf("*");
}
if (arrchk[i] != ZERO)printf("\n");
}
return counter;
私はヒストグラム機能でカウンタが7であるかどうかを確認する必要があります。
'{1,2,3,4,5,6,7}'は配列ではなく、中括弧で囲まれた初期化子です。それ自体では、タイプはありません。 – StoryTeller
[画像](https://en.wikipedia.org/wiki/Collage)が表示されません。 –
私は問題を再現できるように[mcve]を投稿してください。 – user3629249