您可以为数组使用一种格式。我正在使用字符串元素,它应该适用于结构。
#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.
或者,如果您不想使用 NULL ,请改为:
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);