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:
/*
 *--------------------------------------
 * 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(&current_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(&current_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);?
It looks like a bug with os_GetStringInput. I'll try to fix it when I have a chance Smile
MateoConLechuga wrote:
It looks like a bug with os_GetStringInput. I'll try to fix it when I have a chance Smile

and I tried with os_GetCSC(), I set it when I press del key, it will exit, but when I exit the program, I get a ram clear on my calculator, but on CEmu it works fine too.
code for the exit part:

Code:
           if(key==sk_Del)
            {
                //save progress
                ti_CloseAll();
                progress = ti_Open("TYPFILE","w");
                //write all the progress into the appvar
                ti_Write(&current_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);
            }

I compiled it on the ti-planet's project builder, it only have toolchain 7.5, does it matter?
Wait never mind it has nothing to do with input. Your issue is this line:


Code:
char calculations[];

Can you tell me why this is wrong Razz
MateoConLechuga wrote:
Wait never mind it has nothing to do with input. Your issue is this line:


Code:
char calculations[];

Can you tell me why this is wrong Razz

I guess I need to size this variable?
Waaangyi wrote:
I guess I need to size this variable?

Yes, otherwise it is writing to arbitrary memory and corrupting variables.

You can exit a program by just letting the main() function return.
MateoConLechuga wrote:
Waaangyi wrote:
I guess I need to size this variable?

Yes, otherwise it is writing to arbitrary memory and corrupting variables.

You can exit a program by just letting the main() function return.

thanks Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement