學習筆記(14):C語言入門到精通-數組

立即學習:https://edu.csdn.net/course/play/10534/378129?utm_source=blogtoedu

學習目標:

1. 掌握數組的初始化。

2. 知道數組在內存中的存儲方式。

 

示例代碼:

#include <stdio.h>

#define MAX_SIZE 100
#define STAT_MAX_SIZE 127

typedef unsigned int uint32;

int main() {
    char tmp = 0;
    char char_set[MAX_SIZE] = {0};
    uint32 i = 0;
    uint32 stat[STAT_MAX_SIZE] = {0};

    printf("please input chars in line: ");

    while (scanf("%c", &tmp) && tmp != '\n') {
        char_set[i++] = tmp;
    }

    for (i = 0; i < MAX_SIZE && char_set[i] != 0; i++) {
        printf("%c", char_set[i]);
        stat[char_set[i]]++;
    }

    for (i = 0; i < STAT_MAX_SIZE; i++) {
        if (stat[i] == 0) {
            continue;
        }

        printf("%c: %u\n", i, stat[i]);
    }

    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章