2Q その3 (パッチ)

  既存のバイナリデータを更新する



[ patch.cpp ]
  
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct SAVEDATA {
	short Level;
	short HitPoint;
	short MagicPoint;
	short Strength;
	short Defense;
	short Skill;
	short Speed;
	short Ability;
} sd;

char *Title[] = { "Level", "HitPoint", "MagicPoint", "Strength", "Defense", "Skill", "Speed", "Ability" };

void
main( int argc, char *argv[] )
{

	FILE *fp;

	fp = fopen( argv[1], "rb+" );
	if ( fp == NULL ) {
		printf( "%s が OPEN できません\n", argv[1] );
		exit( 1 );
	}

	char buffer[80];
	int i = 0;
	int j;

	memset( (char *)&sd, 0x00, sizeof( struct SAVEDATA ) );
	fread( (char *)&sd, sizeof( struct SAVEDATA ), 1, fp );

	while( 1 ) {
		if ( i == 0 ) {
			printf( "--------------------------\n" );
		}
		printf( "%s : ", Title[i] );
		gets( buffer );

		if ( strcmpi( buffer, "Q" ) == 0 ) {
			break;
		}
		else if ( strcmpi( buffer, "SAVE" ) == 0 ) {
			fseek( fp, 0, SEEK_SET );
			fwrite( (char * )&sd, sizeof( struct SAVEDATA ), 1, fp );
		}
		else if ( strcmpi( buffer, "DISP" ) == 0 ) {
			printf( "--------------------------\n" );
			for( j = 0; j < 8; j++ ) {
				printf( "%s : %d\n", Title[j], *(((short *)((char *)&sd))+j) );
			}
			printf( "--------------------------\n" );
		}
		else if ( buffer[0] == 0x00 ) {
		}
		else {
			switch( i ) {
				case 0:
					sd.Level = atoi( buffer );
					break;
				case 1:
					sd.HitPoint = atoi( buffer );
					break;
				case 2:
					sd.MagicPoint = atoi( buffer );
					break;
				case 3:
					sd.Strength = atoi( buffer );
					break;
				case 4:
					sd.Defense = atoi( buffer );
					break;
				case 5:
					sd.Skill = atoi( buffer );
					break;
				case 6:
					sd.Speed = atoi( buffer );
					break;
				case 7:
					sd.Ability = atoi( buffer );
					break;
			}
		}

		i++;
		if ( i == 8 ) {
			i = 0;
		}

	}

	fclose( fp );

}
  










  infoboard   管理者用   





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ