昨日の続き
ENDをNULLポインタで書き換えることができたのでここにコードを書いておく。
/* * 2006年2月5日 * *str[]の要素数をカウントする */ #include <stdio.h> #include <stdlib.h> #include <string.h> char *month[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", NULL, }; isnull(void *p) { if (p == NULL) { return 1; } else { return 0; } } int count_month(void) { int i = 0; while (!isnull(month[i])) { printf("%d: %s\n", i, month[i]); i++; } return i; } int main(int argc, char *argv[]) { printf("count_month = %d\n", count_month()); return 0; }