Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I am getting this weird issue on my CG-10 where when it gets to a certain point, it freezes up and I have to pull the batteries out to turn it off.

This is my first time using Prizm SDK, but I have programmed quite a bit of C++ in the past (Close enough to C, but I haven't programmed C++ within 9 months but i'm not too rusty).

I am creating a program that will take an input integer, create an array of that size, request values for each element, and then perform forecast predictions on the values (think financing, and each element represents a month, and there are multiple different ways I want to "predict" a specific month).

I think my program is getting hung up around line 133 ("while(i<ARRAY_SIZE){"), where ARRAY_SIZE is an int derived from an int value in a struct (confusing to explain, but I couldn't find any online resources that would have helped me to make it easier).

Here is my code so far (line 133 has a row of forward-slashes right before it, to assist in identification):

Code:
#include <fxcg/keyboard.h >
#include <fxcg/display.h>
#include <CONVERT_syscalls.h>
#define true 1
#define false 0

struct VALUE_GROUP {
  double Value_Complete;
  int Value_Whole;
  int Value_Decimal;
  int Whole_Digit_Count;
  int Decimal_Digit_Count;
  char Char_Value_Whole[14];
  char Char_Value_Whole_2[14];
  char Char_Value_Decimal[14];
  char Char_Value_Decimal_2[14];
};

void print(char cmd,int x,int y, int val){
   if(cmd == 'x')PrintXY(x,y,"--                          ", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
   else if(cmd == 'i'){
      char out[14];
      itoa(val,(unsigned char*)out+2);
      PrintXY(x,y,out, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
   }
}
void print_int(int value,int line){
   char char_val[14];
}

struct VALUE_GROUP KeyToNum(int printWhile){
   struct VALUE_GROUP Return_Value;
   Return_Value.Value_Complete=0;
   Return_Value.Value_Whole=0;
   Return_Value.Value_Decimal=0;
   Return_Value.Whole_Digit_Count=1;
   Return_Value.Decimal_Digit_Count=0;
   
   int decimals = 1;
   int input;
   int active = true;
   
   while(active){
      int value = 0, valid = false;
      GetKey(&input);
      if(input == KEY_CTRL_EXE){
         active = false;
      }else if(input == KEY_CHAR_0){
         value = 0; valid = true;
      }else if(input == KEY_CHAR_1){
         value = 1; valid = true;
      }else if(input == KEY_CHAR_2){
         value = 2; valid = true;
      }else if(input == KEY_CHAR_3){
         value = 3; valid = true;
      }else if(input == KEY_CHAR_4){
         value = 4; valid = true;
      }else if(input == KEY_CHAR_5){
         value = 5; valid = true;
      }else if(input == KEY_CHAR_6){
         value = 6; valid = true;
      }else if(input == KEY_CHAR_7){
         value = 7; valid = true;
      }else if(input == KEY_CHAR_8){
         value = 8; valid = true;
      }else if(input == KEY_CHAR_9){
         value = 9; valid = true;
      }else if(input == KEY_CHAR_DP){
         if(decimals==1){
            decimals*=10; valid = true;
         }
      }
      if(valid && active){
         if(decimals == 1){
            Return_Value.Value_Whole=(Return_Value.Value_Whole*10)+value;
            Return_Value.Whole_Digit_Count++;
         }else if(decimals>1){
            Return_Value.Value_Decimal=(Return_Value.Value_Decimal*10)+value;
            if(Return_Value.Value_Decimal>0){
               Return_Value.Decimal_Digit_Count++;
               decimals*=10;
            }
         }
         itoa(Return_Value.Value_Whole,(unsigned char*)Return_Value.Char_Value_Whole);
         itoa(Return_Value.Value_Whole,(unsigned char*)Return_Value.Char_Value_Whole_2 + 2);
         if(decimals>1){
            itoa(Return_Value.Value_Decimal,(unsigned char*)Return_Value.Char_Value_Decimal);
            itoa(Return_Value.Value_Decimal,(unsigned char*)Return_Value.Char_Value_Decimal_2 + 2);
         }
         if(printWhile){
            PrintXY(1,8,Return_Value.Char_Value_Whole_2,0,TEXT_COLOR_BLACK);
            if(decimals>1){
               PrintXY(Return_Value.Whole_Digit_Count,8,"  .",0x20,TEXT_COLOR_BLACK);
               if(Return_Value.Decimal_Digit_Count>0)PrintXY(Return_Value.Whole_Digit_Count+1,8,Return_Value.Char_Value_Decimal_2,0x20,TEXT_COLOR_BLACK);
            }
         }
      }
   }
   Return_Value.Value_Complete=Return_Value.Value_Whole+(Return_Value.Value_Decimal/decimals);
   return Return_Value;
}
 
void main(void) {
   int event = true, i = 0;
   int input;
   PrintXY(1,1,"--Enter Length:", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
   
   struct VALUE_GROUP ARRAY_SIZE_GROUP = KeyToNum(1);
   int ARRAY_SIZE = ARRAY_SIZE_GROUP.Value_Whole;
   struct VALUE_GROUP ARRAY_GROUP[ARRAY_SIZE];
   double ARRAY[ARRAY_SIZE];
   i=0;
   while(i<ARRAY_SIZE){
      Bdisp_AllClr_VRAM();
      PrintXY(1,1,"--Enter Value: ", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
      print('i',14,1,i+1);
      ARRAY_GROUP[i]=KeyToNum(1);
      ARRAY[i]=ARRAY_GROUP[i].Value_Complete;
      i++;
   }

   event = true;
   while (event) {
      Bdisp_AllClr_VRAM();
      PrintXY(1,1,"--What Do:", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
      PrintXY(3,2,"--1. View List:", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
        GetKey(&input);
      if(input == KEY_CHAR_1){
         Bdisp_AllClr_VRAM();
         i=0;
         int line=1,input_l;
//////////////////////////////////////////////////////////////////////////////////////
         while(i<ARRAY_SIZE){
            PrintXY(1,line,"--[", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
            print('i',3,line,i+1);
            if(i+1>9)PrintXY(6,line,"--]:", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
            else PrintXY(5,line,"--]:", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
            PrintXY(9,line,ARRAY_GROUP[i].Char_Value_Whole_2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
            if(ARRAY_GROUP[i].Decimal_Digit_Count>0){
               PrintXY(9+ARRAY_GROUP[i].Whole_Digit_Count,line,"--.", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
               PrintXY(10+ARRAY_GROUP[i].Whole_Digit_Count,line,ARRAY_GROUP[i].Char_Value_Decimal_2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
            }
            if(line==7){
               PrintXY(1,8,"--Continue (1)?", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
               GetKey(&input_l);
               if(input_l == KEY_CHAR_1){
                  line=1;
                  Bdisp_AllClr_VRAM();
               }
               else{
                  i=ARRAY_SIZE;
                  line++;
               }
            }
         }
         event = false;
         break;
      }else{
         Bdisp_AllClr_VRAM();
         PrintXY(3,8,"--Failed!", TEXT_MODE_NORMAL, TEXT_COLOR_RED);
      }
   }
   KeyToNum(1);
   GetKey(&input);
   return;
}


I was pretty sure I had everything down pat, but if I messed up somewhere, I would greatly appreciate assistance. Thanks[/code]
With stupid hacks to make this compile on my PC (under the theory this isn't a Prizm bug, but just a logic bug), it's clear there's an infinite loop.

Code:
#define true 1
#define false 0

void itoa(int val, char *s) {
    sprintf(s, "%i", val);
}

struct VALUE_GROUP {
  double Value_Complete;
  int Value_Whole;
  int Value_Decimal;
  int Whole_Digit_Count;
  int Decimal_Digit_Count;
  char Char_Value_Whole[14];
  char Char_Value_Whole_2[14];
  char Char_Value_Decimal[14];
  char Char_Value_Decimal_2[14];
};

void print(char cmd, int x, int y, int val) {
  if (cmd == 'x')
    puts("");
  else if (cmd == 'i') {
    char out[14];
    itoa(val, (unsigned char *)out + 2);
    puts(&out[2]);
  }
}
void print_int(int value, int line) { char char_val[14]; }

struct VALUE_GROUP KeyToNum(int printWhile) {
  struct VALUE_GROUP Return_Value;
  Return_Value.Value_Complete = 0;
  Return_Value.Value_Whole = 0;
  Return_Value.Value_Decimal = 0;
  Return_Value.Whole_Digit_Count = 1;
  Return_Value.Decimal_Digit_Count = 0;

  int decimals = 1;
  int input;
  int active = true;

  while (active) {
    int value = 0, valid = false;
    input = getchar();
    if (input == '\n') {
      active = false;
    } else if (input == '0') {
      value = 0;
      valid = true;
    } else if (input == '1') {
      value = 1;
      valid = true;
    } else if (input == '2') {
      value = 2;
      valid = true;
    } else if (input == '3') {
      value = 3;
      valid = true;
    } else if (input == '4') {
      value = 4;
      valid = true;
    } else if (input == '5') {
      value = 5;
      valid = true;
    } else if (input == '6') {
      value = 6;
      valid = true;
    } else if (input == '7') {
      value = 7;
      valid = true;
    } else if (input == '8') {
      value = 8;
      valid = true;
    } else if (input == '9') {
      value = 9;
      valid = true;
    } else if (input == '.') {
      if (decimals == 1) {
        decimals *= 10;
        valid = true;
      }
    }
    if (valid && active) {
      if (decimals == 1) {
        Return_Value.Value_Whole = (Return_Value.Value_Whole * 10) + value;
        Return_Value.Whole_Digit_Count++;
      } else if (decimals > 1) {
        Return_Value.Value_Decimal = (Return_Value.Value_Decimal * 10) + value;
        if (Return_Value.Value_Decimal > 0) {
          Return_Value.Decimal_Digit_Count++;
          decimals *= 10;
        }
      }
      itoa(Return_Value.Value_Whole,
           (unsigned char *)Return_Value.Char_Value_Whole);
      itoa(Return_Value.Value_Whole,
           (unsigned char *)Return_Value.Char_Value_Whole_2 + 2);
      if (decimals > 1) {
        itoa(Return_Value.Value_Decimal,
             (unsigned char *)Return_Value.Char_Value_Decimal);
        itoa(Return_Value.Value_Decimal,
             (unsigned char *)Return_Value.Char_Value_Decimal_2 + 2);
      }
      if (printWhile) {
        puts(Return_Value.Char_Value_Whole_2 + 2);
        if (decimals > 1) {
          puts("  .");
          if (Return_Value.Decimal_Digit_Count > 0)
            puts(Return_Value.Char_Value_Decimal_2 + 2);
        }
      }
    }
  }
  Return_Value.Value_Complete =
      Return_Value.Value_Whole + (Return_Value.Value_Decimal / decimals);
  return Return_Value;
}

void main(void) {
  int event = true, i = 0;
  int input;
  puts("Enter Length:");

  struct VALUE_GROUP ARRAY_SIZE_GROUP = KeyToNum(1);
  int ARRAY_SIZE = ARRAY_SIZE_GROUP.Value_Whole;
  struct VALUE_GROUP ARRAY_GROUP[ARRAY_SIZE];
  double ARRAY[ARRAY_SIZE];
  i = 0;
  while (i < ARRAY_SIZE) {
      puts("Enter value:");
    print('i', 14, 1, i + 1);
    ARRAY_GROUP[i] = KeyToNum(1);
    ARRAY[i] = ARRAY_GROUP[i].Value_Complete;
    i++;
  }

  event = true;
  while (event) {
    // Bdisp_AllClr_VRAM();
    puts("What Do:");
    puts("View List:");

    input = getchar();
    if (input == '1') {
      i = 0;
      int line = 1, input_l;
      while (i < ARRAY_SIZE) {
          puts("[");
        print('i', 3, line, i + 1);
        if (i + 1 > 9)
            puts("]:");
        else
            puts("]:");
        puts(ARRAY_GROUP[i].Char_Value_Whole_2 + 2);
        if (ARRAY_GROUP[i].Decimal_Digit_Count > 0) {
            puts(".");
            puts(ARRAY_GROUP[i].Char_Value_Decimal_2 + 2);
        }
        if (line == 7) {
            puts("Continue (1)?");
            input_l = getchar();
          if (input_l == '1') {
            line = 1;
          } else {
            i = ARRAY_SIZE;
            line++;
          }
        }
      }
      event = false;
      break;
    } else {
      puts("Failed");
    }
  }
  KeyToNum(1);
  getchar();
  return;
}


Going down to where it loops and chopping out the irrelevant bits:

Code:
int i = 0;
while (i < ARRAY_SIZE) {
    /* Print some junk */
}

Conspicuous in its absence: any change to the value of i.
Wow, I feel like such an idiot now. I was sure I put an i++ somewhere in there. Thank you for your help and sorry for inconveniencing you with my silly mistake
One of the hazards of using a system that doesn't support any kind of useful debugging. Smile

I'm curious if FX-CG[CL] would be useful for your testing. It's probably not complete enough to really use, but if you're interested I can prioritize some improvements.
Tari wrote:
One of the hazards of using a system that doesn't support any kind of useful debugging. Smile

I'm curious if FX-CG[CL] would be useful for your testing. It's probably not complete enough to really use, but if you're interested I can prioritize some improvements.


Thanks. I have worked on my program since then and am getting similar crashes, but this time not associated with accidentally stuck loops.

I believe my program is somehow chewing up memory and not destroying it on program exit, not even exiting the program and getting back in resolves the issue.

Basically, what happens is a chosen function/method out of a list of options works successfully the first time, and even after exiting the program, all attempts to call that same or similar function/method crashes the program, usually on a GetKey(&input) call.

The only way I can get my program working successfully past the point of crash is to manually remove some file from storage (that I don't want) or by running the calculator's storage "Optimization" program (which takes 5 minutes...).

Any ideas?
  
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 1 of 1
» All times are GMT - 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