void setDefaultHS() { unsigned int index, file, i; /* Close all open file handles before we try any funny business */ ti_CloseAll(); /* Open a file for writting -- delete it if it already exists */ file = ti_Open("tentenhs", "a+"); if (file) { ti_Rewind(file); ti_Read(&oldHS, sizeof(int), 1, file); } else { oldHS = 0; } ti_Close(file); }
/* Main Function */ void main(void) { ti_var_t myAppVar; int x; strcpy(dataStruct.settings_name, "Settings Saved"); dataStruct.var1 = 10; dataStruct.var2 = 20; /* Close any files that may be open already */ ti_CloseAll(); /* Open a new variable; deleting it if it already exists */ myAppVar = ti_Open(nameAppVar,"w"); /* Make sure we opened okay */ if (!myAppVar) goto err; /* Write the structure to the appvar */ if ((ti_Write(&dataStruct, sizeof(myData_t), 1, myAppVar)) != 1) goto err; /* Let's read it just to make sure we wrote it correctly */ if ((ti_Rewind(myAppVar) == -1)) goto err; ti_Seek(SEEK_SET, 1, myAppVar); if ((ti_Read(&dataStruct, sizeof(myData_t), 1, myAppVar)) != 1) goto err; /* Make sure we read these varaibles correctly too */ if (dataStruct.var1 != 10 && dataStruct.var2 != 20) goto err; printText(0,0,"Read was successful"); /* Get the scan codes */ while( !os_GetCSC() ); err: printText(0,0,"An error occured"); ti_CloseAll(); pgrm_CleanUp(); }