2013年11月16日土曜日

開発環境

C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)のⅡ部(単純なプログラミング)の11章(ビット演算)、11.8(ビットマップグラフィックス)、11.10(プログラミング実習)、実習11-3を解いてみる。

その他参考書籍

実習11-3.

コード

sample.c

#include <stdio.h>

#define X_SIZE 40
#define Y_SIZE 60

char graphics[X_SIZE / 8][Y_SIZE];

#define SET_BIT(x, y) graphics[(x)/8][y] |= (0x80 >> ((x) % 8))
#define CLEAR_BIT(x, y) graphics[(x)/8][y] &= ~(0x80 >> ((x) % 8))
#define TEST_BIT(x, y) (graphics[(x)/8][y] & (0x80 >> ((x) % 8))) > 0

int main()
{
    int loc;
    void print_graphics(void);
    
    for (loc = 0; loc < X_SIZE; loc++){
        SET_BIT(loc, loc);
    }
    print_graphics();
    return (0);
}

void print_graphics(void)
{
    int x;
    int y;
    unsigned int bit;
    
    for (y = 0; y < Y_SIZE; ++y){
        for (x = 0; x < X_SIZE / 8; ++x){
            for (bit = 0x80; bit > 0; bit = (bit >> 1)){
                if ((graphics[x][y] & bit) != 0){
                    printf(".");
                } else {
                    printf("X");
                }
            }
        }
        printf("\n");
    }
}

makefile

CC=cc
CFLAGS=-g

sample: sample.c
 $(CC) $(CFLAGS) -o sample sample.c

clean:
 rm -f sample

入出力結果(Terminal)

$ make
cc -g -o sample sample.c
$ ./sample
.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXX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