學習筆記(13):C語言入門到精通-typedef

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

學習目標:

1. 掌握typedef的使用方法。

 

示例代碼:

#include <stdio.h>
#include <string.h>

typedef char Name[50];
typedef char Type;

typedef char int8;
typedef short int16;
typedef int int32;
typedef long long int64;

typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;

typedef int32 Count;
typedef uint32 Bid;

typedef struct {
    Name name;
    Type type;
    Count count;
    Bid book_id;
} Book;

int main() {
    Book book;
    memset(&book, 0, sizeof(book));

    printf("please input book's name: ");
    scanf("%s", book.name);
    printf("please input book's type: ");
    scanf("\n%c", &book.type);
    printf("please input book's count: ");
    scanf("%d", &book.count);
    printf("please input book's id: ");
    scanf("%u", &book.book_id);

    printf("name: %s, type: %c, count: %d, id: %u\n", book.name, book.type, book.count, book.book_id);

    return 0;
}

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