🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fj.lang.c
Article #523

共用体について

#523
From: u0672014
Date: Sat, 21 Mar 1998 00:00
38 lines
1413 bytes
明解C言語という本で勉強しています。共用体のところの演習問題で、
student型の配列を定義し、全員のデータを表示するプログラムを作成せよ。
男性であれば体重を、女性であれば3サイズを表示することとする、
というのがあります。ここで女性の3サイズのデータをunionの中の
struct{int b; int w; int h;}に対応させることができません。
初めは、{87,56,90}のようにすれば良いだろうと思っていましたが、
できませんでした。

どなたか分かる人がいたら教えて下さい。
#include<stdio.h>

typedef struct{
  char name[20];
  int height;
  long schols;
  int sex;
  union{
    float weight;
    struct{
      int b;
      int w;
      int h;
    }bwh;
  }pro;
}student;

int main(void)
{
  int i;
  student date[]={
    {"Takeshi",171,80000,0,60.0},
    {"Hiroko",154,50000,1,{87,56,90}}
   };

ーーーーーーーーーーーーーーーーーーーー
 柴田 英司
 u0672014@sci.hiroshima-u.ac.jp
Technical Details
Message-ID: <6f040o$gln@alpha01.sci.hiroshima-u.ac.jp>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS
X-Google-Thread: 106434,17e1ebf0b9e3511f,start
X-Google-Attributes: gid106434,public
From: u0672014@alpha03.sci.hiroshima-u.ac.jp
Subject: 共用体について
Date: 1998/03/21
Message-ID: <6f040o$gln@alpha01.sci.hiroshima-u.ac.jp>
X-Deja-AN: 337116857
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
Organization: Rigakubu Kyoiku System
Newsgroups: fj.lang.c