「C言語」typedef struct による構造体の定義サンプル

サンプルコード

#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, "JavaScript入門");
   strcpy( book.author, "Yamada"); 
   strcpy( book.subject, "Java入門");
   book.book_id = 12345;
 
   printf( "book title : %s\n", book.title);
   printf( "book author : %s\n", book.author);
   printf( "book category : %s\n", book.subject);
   printf( "book  ID : %d\n", book.book_id);
 
   return 0;
}

実行結果:
book title : JavaScript入門
book author : Yamada
book category : Java入門
book ID : 12345

C++

Posted by arkgame