不完整的用户输入直方图 C

Incomplete User Input Histogram C

有一个不完整的直方图需要为项目完成。

   #include <stdio.h>



/**
    * Prints a histogram to the screen using horizontal bar chart.
    * Parameters:
    *   list - a list of integers
    *   n - the number of values in the list
    */
    void printHistogram ( int *hist, int n );

   /**
 * This program requests data from the user and then
 * computes and prints a histogram. You may assume that
     * the data values entered are in the range of 0 to 9.
    */
   int main ( void )
   {


int i, n;


// Data entry
//
printf ("How many values in your data set? ");
scanf ("%d", &n);

int list[n];
for (i=0; i < n; i++) {
    printf ("Enter a value: ");
    scanf ("%d", &list[i]);
}

// Processing data to compute histogram

int hist[10];    


// Printing histogram
printHistogram ( hist, 10);

return 0;
}



void printHistogram ( int *list, int n )
{
int i, j;

for (i=0; i < n; i++) {
    printf ("[%d] ", i);
    for (j = 0; j < list[i]; j++)
        printf ("*");
    printf ("\n");
  }
 }

您为实际解决方案提供的信息太少,但无论如何。
所以,我假设你想打印一个直方图,其中包含 1-9 之间的整数的出现次数(至少,这是我的理解)。
一种可能的方法是创建一个整数数组,该数组将保留每个整数出现的次数。它显然有 10 个项目。当你到达输入时,对于你遇到的每个整数,你将增加数组中的相应项目。请注意,您不需要在数组中搜索每个整数。
如果你想计算单词字符串的出现次数,这有点复杂,因为它需要使用结构,但它基于相同的想法。