🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by u0672014 Sat, 21 Mar 1998 00:00
共用体について
#523
Author: 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
Re: 共用体について
#633
Author: Eiji Shibata
Date: Tue, 24 Mar 1998 00:00
23 lines
1481 bytes
<6f040o$gln@alpha01.sci.hiroshima-u.ac.jp>の記事において
u0672014@alpha03.sci.hiroshima-u.ac.jpさんは書きました。

>> 明解C言語という本で勉強しています。共用体のところの演習問題で、
>> student型の配列を定義し、全員のデータを表示するプログラムを作成せよ。
>> 男性であれば体重を、女性であれば3サイズを表示することとする、
>> というのがあります。ここで女性の3サイズのデータをunionの中の
>> struct{int b; int w; int h;}に対応させることができません。

student型の配列を定義し、データを読み込んでいく。

自分で書いた質問ですが、
対応のさせ方は間違っていませんでしたが、
問題は、unionでいったんfloat型のデータを使った後、
struct型のデータを使うことができなくなることでした。逆も又しかりです。


これじゃあ union の意味ないか。

==========================================
柴田英司
広島大学
Re: 共用体について
#635
Author: Kusakabe Youichi
Date: Tue, 24 Mar 1998 00:00
18 lines
1095 bytes
u0672014@alpha03.sci.hiroshima-u.ac.jp wrote:
: $BL@2r#C8@8l$H$$$&K\$GJY6/$7$F$$$^$9!#(B

$B652J=q$rFI$_$^$7$g$&!#(B
$B!V6&MQBN$N=i4|2=$O!"$=$N:G=i$N%a%s%P!<$N7?$NCM$G$N$_$d$C$F$h$$!W(B
$B$C$F=q$$$F$"$j$^$9!#(B

$B$H$3$m$G!"BN=E$,(Bfloat$B$G!"(B3$B%5%$%:$,$=$l$>$l(Bint$B$J$N$O$J$<$G$7$g$&(B ?
($B$G!"?HD9$O(Bint)

$B$J$s$@$+!"$`$j$K(Bunion$B$r;H$o$;$h$&$H$7$F$$$kIT<+A3$JN}=,LdBj$N(B
$B$h$&$J5$$,$7$^$9$,(B...$B!#(B

  $B%X(B_$B%X(B   ________________________
$B%_!&!&(B $B%_(B  void@merope.opus.or.jp
 (  $B!k(B )$B!A(B            $BF|2<ItM[0l(B
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads