#include <stdlib.h>
#include <stdio.h>
#include "histo.h"
int main(int args, char *argv[])
{
int histo[256];
if (args == 2)
{
init_histogram(histo);
cons_histogram(argv[1], histo);
display_histogram(histo);
}
else
exit(1);
return 0;
}
histo.h
#define MAX_CHAR 255 // largest ASCII(Extended) value for characters
typedef unsigned char byte; // may be useful for casting(s)
void init_histogram(int histo[]); // set all elements of the histogram to zero
void cons_histogram(const char string[], int histo[]); // construct the histogram from string
void most_frequent(const int histo[], char* ret_val); // report a most occurring character
void display_histogram(const int histo[]); // display the histogram sparsely
我給這個main.c和histo.h實現了頭文件中的那些方法之後的histo.c文件。我對int數組的歷史感到困惑。 display_histogram只需要一個參數,它爲您打印輸出:如何使用指針/數組在C中實現這些方法?
% ./main hgfjkddjkrui3
3 appeared 1 times
d appeared 2 times
f appeared 1 times
g appeared 1 times
h appeared 1 times
i appeared 1 times
j appeared 2 times
k appeared 2 times
r appeared 1 times
u appeared 1 times
d是一個最經常發生 任何人都可以向我解釋都應該被存儲在HISTO []爲了得到這個輸出什麼樣的價值觀?