]> git.piffa.net Git - arduino/blob - books/beginning_c_code/Chapter09/Listing9_3/Listing9_3.ino
first commit
[arduino] / books / beginning_c_code / Chapter09 / Listing9_3 / Listing9_3.ino
1 /*
2   Purpose: To illustrate the relationship between two-dimensional
3  arrays and pointers.
4  Dr. Purdum, August 21, 2012
5  */
6 #define DAYSINWEEK 7
7 #define CHARSINDAY 10
8
9 void setup() {
10   Serial.begin(9600);   // Serial link to PC
11 }
12
13 void loop() {
14   static char days[DAYSINWEEK][CHARSINDAY] = 
15   {
16     "Sunday", "Monday", "Tuesday","Wednesday", 
17     "Thursday", "Friday", "Saturday"  };
18   int i, j;
19   char *ptr, *base;
20
21   base = days[0];      // Different for N-rank arrays where N > 1
22   for (i = 0; i < DAYSINWEEK; i++) {
23     ptr = base + (i * CHARSINDAY);
24     Serial.print((int) ptr);  // Show the lvalue
25     Serial.print(" ");
26     for (j = 0; *ptr; j++) {
27       Serial.print(*ptr++);    // Show one char
28     }
29     Serial.println();
30   }
31   Serial.flush();
32   exit(0);  
33 }
34
35
36 \r