आप अपने सरणी के लिए प्रारूप का उपयोग कर सकते हैं। मैं स्ट्रिंग तत्वों का उपयोग कर रहा हूं, इसे संरचना के लिए काम करना चाहिए।
#define NULL ""
#define SAME 0
static char *check[] = {
"des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
"blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
"camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
"lzo", "cts", "zlib", NULL
}; // 38 items, excluding NULL
मुख्य()
char **algo = check;
int numberOfAlgo = 0;
while (SAME != strcmp(algo[numberOfAlgo], NULL)) {
printf("Algo: %s \n", algo[numberOfAlgo++]);
}
printf("There are %d algos in the check list. \n", numberOfAlgo);
आप उत्पादन मिलना चाहिए में
: वैकल्पिक रूप से
Algo: des
:
:
Algo: zlib
There are 38 algos in the check list.
, आप शून्य का उपयोग नहीं करना चाहते हैं, इस के बजाय कार्य करें:
numberOfAlgo = 0;
while (*algo) {
printf("Algo: %s \n", *algo);
algo++; // go to the next item
numberOfAlgo++; // count the item
}
printf("There are %d algos in the check list. \n", numberOfAlgo);
क्योंकि 'sizeof() 'एक संकलन-समय ऑपरेटर है और सदस्य फ़ंक्शन नहीं है (जैसा कि C++ में है)। – ruslik