To tylko jedna z 2 stron tej notatki. Zaloguj się aby zobaczyć ten dokument.
Zobacz
całą notatkę
Initialization of pointer arrays • Problem: write a function month_name(n) , returning the name of the n -th month (in the form of a pointer to a string) • We will use a static array • month_name contains an array of pointers to 13 strings • … returns a pointer to one of them • How to initialize that array • Call: printf(”The 5th month is: %s\n”, month_name(5)); /* month_name: return name of n-th month */ /* acc. to K&R */ char *month_name(int n) { static char *name[] = { "Illegal month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; return (n 12) ? name[0] : name[n]; }
... zobacz całą notatkę
Komentarze użytkowników (0)