![]() ![]() ![]() | strings/string-array-alternative.c - Programmet med alternativ array erklæring. | Lektion 10 - slide 47 : 51 Program 3 |
#include <stdio.h> #include <ctype.h> int main(void) { /* char *numbers[] = {"one", "two", "three"}; */ char numbers[3][6] = {"one", "two", "three"}; char ch1, ch2, ch3, ch4, ch; int i; ch1 = **numbers; // 'o' ch2 = numbers[0][0]; // 'o' ch3 = *(*(numbers+1) + 1); // 'w' ch4 = numbers[2][3]; // 'e' printf("ch1 = %c, ch2 = %c, ch3 = %c, ch4 = %c\n", ch1, ch2, ch3, ch4); /* Printing the 18 in numbers characters */ for(i = 0; i < 18; i++){ ch = *(&numbers[0][0] + i); if (isgraph(ch)) printf("%c", ch); else printf("%c", '-'); } printf("\n"); /* Printing 3 strings */ for(i = 0; i < 3; i++) printf("%s\n", numbers[i]); printf("\n"); return 0; }