「C言語」構造体とtypedefを利用するサンプル

サンプルコード
#include <stdio.h>
#include <string.h>

typedef struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
} Book;

int main( )
{
Book book;

strcpy( book.title, “java");
strcpy( book.author, “ctoit");
strcpy( book.subject, “language");
book.book_id = 12345;

printf( “book title: %s\n", book.title);
printf( “book author : %s\n", book.author);
printf( “book subject : %s\n", book.subject);
printf( “book ID : %d\n", book.book_id);

return 0;
}

結果:
book title: java
book author : ctoit
book subject : language
book ID : 12345

C++

Posted by arkgame