1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[]) {
    char** daze = malloc(sizeof(*daze) * 4);
    // Array of char*.  Ex:  whatis daze[2] should print char*  (not char)

    // EXERCISE
    // Q: What should go in the sizeof(…) operator
    // A: *daze

    int width = 4;
    for(int i = 0; i < 4; i++) {
        daze[i] = malloc(sizeof(**daze) * width);
        // daze[i] should be an array of char.
        // daze[i][j]  would be a char

        // EXERCISE
        // Q: What should you put in sizeof(   )?
        // A: **daze  --OR--  daze[0][0]  --OR--  daze[999999999][999999999]
    }
    memcpy(daze[0], "**_*", 4);
    memcpy(daze[1], "*_**", 4);
    memcpy(daze[2], "*__*", 4);
    memcpy(daze[3], "*_**", 4);

    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 4; j++) {
            fputc(daze[i][j], stdout);
        }
        fputc('\n',       stdout);
    }

    return EXIT_SUCCESS;
}

/*
OUTPUT:

**_*
*_**
*__*
*_**

*/
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2017 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.