My appvar keeps returning really large values I did not input. I was wondering how to fix this. I am aware my code is poorly written and a mess. Thank you.
Code:
Code:
#include <tice.h>
#include <keypadc.h>
#include <graphx.h>
#include <fileioc.h>
static void PrintTime(float elapsed)
{
real_t elapsed_real;
char str[10];
elapsed_real = os_FloatToReal(elapsed <= 0.001f ? 0.0f : elapsed);
os_RealToStr(str, &elapsed_real, 8, 1, 2);
os_SetCursorPos(0, 0);
os_PutStrFull(str);
}
int main(void){
char str[10];
ti_var_t LyricAppvar;
float LyricVal;
float elapsed = 0;
real_t elapsedREAL;
timer_Set(1, 0);
LyricAppvar = ti_Open("Lyrics", "r+");
if(LyricAppvar == 0){
os_PutStrLine("Yeah id int syudj");
LyricAppvar = ti_Open("Lyrics", "w+");
}
ti_Read((void *)&LyricVal, 3, 1, LyricAppvar);
while (!os_GetCSC());
os_ClrHome();
PrintTime(LyricVal);
while (!os_GetCSC());
//PrintTime(0.0f);
timer_Disable(1);
timer_Set(1, 0);
while (!os_GetCSC());
timer_Enable(1, TIMER_32K, TIMER_0INT, TIMER_UP);
do
{
float elapsed = (float)timer_GetSafe(1, TIMER_UP) / 32768;
PrintTime(elapsed);
} while (!os_GetCSC());
elapsed = (float)timer_GetSafe(1, TIMER_UP) / 32768;
elapsed = elapsed * 100;
//Rounds it off to be a 3(usually) digit number
elapsedREAL = os_FloatToReal(elapsed <= 0.001f ? 0.0f : elapsed);
elapsedREAL = os_RealRoundInt((const real_t *)&elapsedREAL);
//Prints again
os_RealToStr(str, &elapsedREAL, 8, 1, 2);
os_SetCursorPos(5, 5);
os_PutStrFull(str);
LyricAppvar = ti_Open("Lyrics", "r+");
ti_Write((const void*)&elapsedREAL, sizeof(elapsedREAL), 1, LyricAppvar);
while (!os_GetCSC());
timer_Disable(1);
ti_SetArchiveStatus(true, LyricAppvar);
ti_Close(LyricAppvar);
return 0;
}