0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

未経験から学ぶ組み込み開発|『独習 C』で理解したポイントと実験記録

Posted at

【独習 C】を読んで学んだこと・実践したこと

📚 読んだ本

  • タイトル:独習 C
  • 著者:arton
  • 出版社:翔泳社
  • 読んだ目的:
    • C言語の基礎を固めるため

🧠 本から学んだ重要ポイント

  • コマンドライン引数の使用方法
  • アドレスとポインターと配列の関係
  • ファイルIOの理解
  • 構造体と共有体の違い
  • マクロの基礎知識

🛠 実際に試したこと・コード例

ビットフィールドの基礎知識を習得するために以下のコードを実装。

#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
typedef struct {
        bool eco_mode : 1;
        unsigned shift_place : 3;
        bool side_brake : 1;
        int engine;
        int blinker : 2;
        unsigned swi : 3;
} CAR;

static char *ECO_MODE[] = {"ON", "OFF"};
static char *SHIFT_PLACE[] = {"P", "R", "N", "D", "L"};
static char *SIDE_BRAKE[] = {"ON", "OFF"};
static char *BLINKER[] = {"left", "center", "right"};
static char *SWI[] = {"stop", "ig ON", "engine ON", "starter"};

void print_car(const CAR *p) {
        printf("エコモード:%s, シフト位置:%s,サイドブレーキ:%s, エンジン回転数:%i, ウィンカー位置:%s, スイッチ:%s\n",
                ECO_MODE[p->eco_mode], SHIFT_PLACE[p->shift_place], SIDE_BRAKE[p->side_brake], p->engine, BLINKER[p->blinker + 1], SWI[p->swi]);
}

int main() {
        CAR car[] = {
                {0, 0, 1, 0, 0, 0},
                {1, 3, 0, 1500, 0, 2},
                {0, 2, 0, 800, -1, 2},
        };
        for (int i = 0; i < sizeof car / sizeof car[0]; i++) {
                print_car(&car[i]);
        }
}

🚀 今後の展望

重要ポイントにある5個のポイントを応用したポートフォリオの作成を行う。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?