ページ 11

構造体の配列を使用してポインタで出力する

Posted: 2012年5月29日(火) 16:17
by tomoya
はじめて投稿します。
構造体の配列を使用してポインタで出力したいのですが、どうやればいいのかわかりません。

以下のソースを元に作りたいと考えています。
教えていただけないでしょうか?宜しくお願いします。

コード:

#include <stdio.h>
#include <stdlib.h>

#define NUMBER 7/*人数*/

typedef struct {/*全情報の構造体*/
	char name[20];/*名前*/
	int  calender1;/*月*/
	int  calender2;/*日*/
	char week[11];/*曜日*/
}gstaff;

void display(void);

int main(void)
{

	display();
	return EXIT_SUCCESS;
}


void display(vod)
{
	int count = 0;

	// 構造体の配列にデータ入力
	gstaff member[]={
				{"AG",6,4,"Monday"},
				{"TOTORO",6,8,"Friday"},
				{"NEGA",6,1,"Friday"},
				{"Kawashima",6,1,"Friday",},
				{"tarou",6,1,"Friday"},
				{"tana",6,1,"Friday"},
				{"sentou",6,1,"Friday"}
	};

	for( count = 0; count < NUMBER; count++ )
	{
		printf("----------------------------------------\n");
		printf("%s %d/%d %s %s\n", 
member.name[count], 
member.calender1[count], 
member.calender2[count],	                  
 member.week[count], );
		printf("----------------------------------------\n");
	}

} 

Re: 構造体の配列を使用してポインタで出力する

Posted: 2012年5月29日(火) 16:23
by nil
printf( "%s", member[ count ].name );
ではダメですか?

Re: 構造体の配列を使用してポインタで出力する

Posted: 2012年5月29日(火) 16:54
by box
tomoya さんが書きました:

コード:

member.name[count], 
member.calender1[count], 
member.calender2[count],	                  
 member.week[count], );
[count]を書く場所が、すべて間違っています。