arrow_operaterプロジェクト

arrow_operater.c

/*------------------------------------------------------------------------------
 * Title: arrow_operater
 * Project: arrow_operater
 * Source: arrow_operater.c
 * Author: B.G
 * Group: B.G
 * Created: 13:47 2009/12/11
 * Last Modified: 13:47 2009/12/11
 * ---------------------------------------------------------------------------*/
 
/* ヘッダファイルのインクルード */
#include <stdio.h> /* stdio.hのインクルード */
 
/* 構造体の定義 */
/* 構造体struct_test */
struct struct_test{ /* 整数値data_iと文字列data_strを要素にもつ構造体struct_testの定義 */
  int data_i; /* 整数値を格納するint型要素data_i */
  char data_str[10]; /* 文字列を格納する要素数10のchar型配列data_str */
};
 
/* main関数 */
int main(void){
 
  /* 構造体・ポインタの宣言 */
  struct struct_test test1; /* struct_test型の構造体変数test1の宣言 */
  struct struct_test *p_strc; /* struct_test型の構造体変数へのポインタp_strcの宣言 */
 
  /* test1のアドレスをポインタp_strcに格納 */
  p_strc = &test1; /* &演算子で取得したtest1のアドレスをp_strcに格納 */
 
  /* 整数値の入力 */
  printf("p_strc->data_i:"); /* data_iに整数値を格納 */
  scanf("%d", &p_strc->data_i); /* scanfでp_strc->data_iに整数値を格納する */
 
  /* 文字列の格納 */
  printf("p_strc->data_str:"); /* data_strに文字列を格納 */
  scanf("%s", p_strc->data_str); /* scanfでp_strc->data_strに文字列を格納する */
 
  /* 構造体の各要素(およびポインタが指す構造体の各要素)の出力 */
  printf("test1.data_i = %d\n", test1.data_i); /* printfでtest1の整数値要素data_iを出力 */
  printf("test1.data_str = %s\n", test1.data_str); /* printfでtest1の文字列要素data_strを出力 */
  printf("p_strc->data_i = %d\n", p_strc->data_i); /* printfでp_strcの指す構造体の要素data_iを出力 */
  printf("p_strc->data_str = %s\n", p_strc->data_str); /* printfでp_strcの指す構造体の要素data_strを出力 */
 
  /* プログラムの終了 */
  return 0;
 
}
 

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2010年07月08日 14:29