誕生日管理プログラム(データ保存まで出来るように)

kerotan0820
記事: 91
登録日時: 14年前

誕生日管理プログラム(データ保存まで出来るように)

投稿記事 by kerotan0820 » 13年前

データの読み込みはできないけど、テキストファイルへの書き込みはできるようになりました!

CODE:

#include 
#include 
#include 
#include 

static int quantity=0;

    /*************************************************************** 
	          ▲ 名前、生年月日の構造体▲
	***************************************************************/
struct data1 {

	char  name[30];  /*   名前   */
	int   year;      /*    年    */
	int   manth;     /*    月    */
	int   day;       /*    日    */

}birth[200];


    /***************************************************************
	              ■新規データの入力、データ編集用関数■
    ***************************************************************/
	void inputdata( struct data1 birth[] )
	{
		char name1[30];

		printf("名前:"); scanf("%s",name1); //名前を入力
		strcpy(birth[ quantity ].name , name1);
		
		//birth構造体の quantity(データ数)に応じた場所へ入力
		printf("西暦:"); scanf("%d",&birth[ quantity ].year);
		printf(" 月:"); scanf("%d",&birth[ quantity ].manth);
		printf(" 日:"); scanf("%d",&birth[ quantity ].day);
		
		quantity+=1;
	}

    /***************************************************************
	                ■保存データ 一覧表示関数■
    ***************************************************************/
	void indicate_data(void)
	{
		int i;

		if(quantity != 0 )
		{
			for(i=0; i");
		scanf_s( "%d", &menu ); //
		printf("\n");
		
		switch (menu){

        case 1: // データの新規登録
			inputdata( birth ); //■構造体への名前,生年月日入力関数■
			write_data( birth ); //■テキストデータのデータ書き込み関数■
			printf("\n登録が完了しました\n");
		    while(kbhit()!=1);
			break;

		case 2: // データの編集
			break;

		case 3: // 登録データ一覧表示
			indicate_data( birth ); //■データ一覧表示関数■
		    while(kbhit()!=1);
	        break;

		case 4: // 終了
			exit(1);

		default: // 入力エラー
		    printf("1~3以外の値が入力されました\n");
			break;
			system("cls");
		} //switch

	} //while
	
	return 0;

}//main

突っ込みどころ満載だと思いますが><;;

読み込みはどのようにするか…。

おそらく、最初の30文字が名前で、4文字が西暦、2文字が月、2文字が日にちという並びなので、それぞれ ループで一文字ずつ読みこもうと思ってます。

ところで、テキストファイルに一度出力された数字や文字は、全て文字列という事になっちゃうんですよね...?
となると、文字と数字の変換とか必要になるのですかね…。

うひー・・・。 でも、あと一歩です。たぶん!


もうすぐで3年生になり、課題研究も始まるので早い所これを完成させてしまいたいです!^^

ISLe
記事: 2650
登録日時: 14年前

Re: 誕生日管理プログラム(データ保存まで出来るように)

投稿記事 by ISLe » 13年前

fprintfで書き出すならfscanfで読み込むように設計すると良いと思います。

kerotan0820
記事: 91
登録日時: 14年前

Re: 誕生日管理プログラム(データ保存まで出来るように)

投稿記事 by kerotan0820 » 13年前

ISLeさん>>
確かに統一したほうがまとまりがあって良いですよね。
fscanfに直してみたいと思います。
最後に編集したユーザー kerotan0820 on 2012年4月05日(木) 23:25 [ 編集 2 回目 ]