hello, I am new to toolchain compiler and after learning by reading examples, I wrote my first program, it generates a random equation and you type it on your calculator, it is intended to speed up my typing speed on calculator to get ready for UIL calculator application, but when I am trying to exit the program on a real calculator, the calculator freezes, but on the CEmu emulator it works fine, here is the source code
Code:
it just don't work, no matter how hard I tried, it just freezes after I typed in EXIT
and by the way, is there any other way of exiting a program than exit(0);?
Code:
/*
*--------------------------------------
* Program Name:TYPINGADV
* Author:Waaangyi
* License:None
* Description:Typing C to train your typing speed on calculator
*--------------------------------------
*/
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>
/* Standard headers */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fileioc.h>
/* Put function prototypes here */
void printText(const char *text, uint8_t xpos, uint8_t ypos);
/* Put all your code here */
void main(void) {
const char *clean_up_string = " ";
uint24_t current_random_number_order;
char lval[12];
char rval[12];
int random_int;
bool first_input = true;
char calculations[];
int8_t oper_rand;
char user_input[10];
int8_t delay_time=23;
char backup_cal[] = "Random";
uint8_t current_size = 0;
sk_key_t key ;
int i = 0;
uint24_t Temp_order;
ti_var_t progress;
ti_CloseAll();
progress = ti_Open("TYPFILE","r");
if (progress)
{
ti_Read(¤t_random_number_order,sizeof(uint24_t),sizeof(current_random_number_order)/sizeof(uint24_t),progress);
ti_CloseAll();
}
else
{
current_random_number_order = 1;
}
for (Temp_order=1; Temp_order<current_random_number_order; Temp_order++)
{
randInt(1,999);
randInt(1,4);
randInt(1,999);
}
while(1) {
random_int = randInt(1,999);
sprintf(lval,"%d",random_int);
strcpy(calculations,lval);
oper_rand = randInt(1,4);
switch(oper_rand)
{
case 1:
strcat(calculations,"-");
break;
case 2:
strcat(calculations,"+");
break;
case 3:
strcat(calculations,"*");
break;
case 4:
strcat(calculations,"/");
break;
}
random_int = randInt(1,999);
sprintf(rval,"%d",random_int);
strcat(calculations,rval);
os_ClrHome();
strcat(calculations,": ");
os_GetStringInput(calculations,user_input,10);
if(strncmp(user_input,"EXIT",4)==0)
{
//save progress
ti_CloseAll();
progress = ti_Open("TYPFILE","w");
//write all the progress into the appvar
ti_Write(¤t_random_number_order, sizeof(uint24_t), sizeof(current_random_number_order)/sizeof(uint24_t), progress);
//archive appvar
ti_SetArchiveStatus(true,progress);
ti_CloseAll();
os_ClrHome();
exit(0);
}
current_random_number_order++;
}
}
/* Draw text on the homescreen at the given X/Y location */
void printText(const char *text, uint8_t xpos, uint8_t ypos) {
os_SetCursorPos(ypos, xpos);
os_PutStrFull(text);
}
it just don't work, no matter how hard I tried, it just freezes after I typed in EXIT
and by the way, is there any other way of exiting a program than exit(0);?