Mail Archives: djgpp/2005/04/11/19:46:06
>I'm having a problem saving a struct to disk using DJGPP. Normally I'd
think
>the problem was me but in view of the fact that it works under SOME
>circumstances, I'm not sure. Here's the details.
>
>
>
looks like someones homework :-)
As a matter of fact, .... No, actually I'm attempting to write an engine
simulation program and a drag race simulation program. I had already done most
of the work in QuickBASIC 4.5 when I opted to try to learn C so that I could
compile it on other platforms (Linux, mostly for the clustering ability).
Soooo, here's the kicker. I'm also using 2 other struct's. Here's one of
them:
/* -----------------12/24/04 1:46PM------------------
this is permanent structure and saved to disk with
file extension .KRM
--------------------------------------------------*/
#ifndef BIKE_MAIN_H /* these factors normally aren't changeable */
#define BIKE_MAIN_H
#ifndef GLOBAL_BIKE_MAIN
extern
#endif
struct bike_main {
char filename[12]; /* 8 + . + 3 */
float wgt; /* weight of bike and rider */
float wb; /* wheelbase */
float cgx; /* horizontal center of gravity */
float cgy; /* vertical center of gravity */
float p; /* primary gear ratio */
unsigned short y; /* number of gears */
float g[15]; /* gear ratios */
float a; /* aerodynamic drag factor */
float b; /* aerodynamic drag factor */
float c; /* aerodynamic drag factor */
char bike_main_note_1[70];
char bike_main_note_2[70];
char bike_main_note_3[70];
char bike_main_note_4[70];
char bike_main_note_5[70];
char bike_main_note_6[70];
} bike_main_0 ;
typedef struct bike_main BIKE_MAIN;
BIKE_MAIN bike_main_0;
#endif
The get, save, read, and display functions are all exactly the same as per my
previous post except the filename and extension gets changed (all I did was
cut and paste). Those exact same routines work exactly as expected with the
other 2 struct.
Here's an example of how I'm calling those functions:
/* -----------------3/4/05 8:51AM--------------------
this menu allows user to read data from file
--------------------------------------------------*/
void file_read_menu(void)
{
int ans = 0;
int max_len = 0;
char string[max_len];
while (1)
{
char sec_name[]="Read Data from FILE";
heading(sec_name);
clr_area(4,22,1,78);
locate(5,5);
printf("Read Basic Bike Data From File ......................... 1");
locate(6,5);
printf("Read Variable Bike/Launch Data From File ............... 2");
locate(7,5);
printf("Read RPM/Torque/Horsepower Data From File .............. 3");
locate(17,5);
printf("RETURN TO PRIOR MENU ................................... R");
locate(20,5);
printf("Enter your choice - ");
get_input(20, 26, string, 2);
if ((*string == 'r') || (*string == 'R'))
{
return ;
}
ans = atoi(string);
switch (ans)
{
case 1: /* read basic bike data */
file_read_basic(&bike_main_0);
break;
case 2 : /* read variable data */
file_read_opt(&bike_opt_0);
break;
case 3 : /* read torque/hp data */
file_read_power(&power_0);
break;
default:
wrong();
break;
}
}
return ;
}
Does this additional info help?
Willy
********************************************************************
Keller Racing
Performance by Design
KellerRcng AT cs DOT com
http://www.bylleet.com/keller_racing
http://ourworld.compuserve.com/homepages/nostalgia_drag_bike
SUPPORT YOUR LOCAL DRAG RACER!!
********************************************************************
- Raw text -