함수에 배열을 보내려고하면 오류가 발생합니다.배열을 함수 인수로 올바르게 전달하는 방법은 무엇입니까?
이 내 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