andymwat wrote:
Waaangyi wrote:
I don't know if it is my code's problem or the toolchain has a bug, it shows that weird symbol, when I exit the program there is no ram clear, it appears as soon as I run the program. (I am pretty new to toolchain)
Code:
Code:
////////////////////////////////////////
// CFACTOR 1.0
// Author: Waaangyi
// License: None
// Description: Factor family version 6
////////////////////////////////////////
/* 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>
/* Other available headers: stdarg.h, setjmp.h, assert.h, ctype.h, float.h, iso646.h, limits.h, errno.h */
/* Put function prototypes here */
void printText(const char *text, uint8_t xpos, uint8_t ypos);
void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos);
/* Put all your code here */
void main(void)
{
char a[10];
char b[10];
char c[10];
uint8_t current_size = 0;
const uint8_t delay_time=23;
uint8_t times = 1;
const char cleanup[26] = " ";
bool first_input = true;
const uint8_t max_size = 8;
sk_key_t key = sk_Prgm;
os_ClrHome();
printText("THE FASTEST VERSION EVER!",0,0);
printText("FINDER 2.0",0,1);
printText("VERSION 6",0,2);
printText("9 DIGIT MAX",0,3);
printText("FORM:AX^2+BX+C",0,4);
key_input:
first_input = true;
printText(cleanup,0,6);
printText(cleanup,0,8);
if (times==1)
printText("A:",0,5);
if (times==2)
printText("B:",0,5);
if (times==3)
printText("C:",0,5);
while(key!=sk_Enter || current_size==0)
{
key = os_GetCSC();
if (key==sk_1)
{
if (first_input)
{
if(times == 1)
strcpy(a,"1");
if(times == 2)
strcpy(b,"1");
if(times == 3)
strcpy(c,"1");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"1");
if(times == 2)
strcat(b,"1");
if(times == 3)
strcat(c,"1");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_2)
{
if (first_input)
{
if(times == 1)
strcpy(a,"2");
if(times == 2)
strcpy(b,"2");
if(times == 3)
strcpy(c,"2");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"2");
if(times == 2)
strcat(b,"2");
if(times == 3)
strcat(c,"2");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_3)
{
if (first_input)
{
if(times == 1)
strcpy(a,"3");
if(times == 2)
strcpy(b,"3");
if(times == 3)
strcpy(c,"3");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"3");
if(times == 2)
strcat(b,"3");
if(times == 3)
strcat(c,"3");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_4)
{
if (first_input)
{
if(times == 1)
strcpy(a,"4");
if(times == 2)
strcpy(b,"4");
if(times == 3)
strcpy(c,"4");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"4");
if(times == 2)
strcat(b,"4");
if(times == 3)
strcat(c,"4");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_5)
{
if (first_input)
{
if(times == 1)
strcpy(a,"5");
if(times == 2)
strcpy(b,"5");
if(times == 3)
strcpy(c,"5");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"5");
if(times == 2)
strcat(b,"5");
if(times == 3)
strcat(c,"5");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_6)
{
if (first_input)
{
if(times == 1)
strcpy(a,"6");
if(times == 2)
strcpy(b,"6");
if(times == 3)
strcpy(c,"6");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"6");
if(times == 2)
strcat(b,"6");
if(times == 3)
strcat(c,"6");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_7)
{
if (first_input)
{
if(times == 1)
strcpy(a,"7");
if(times == 2)
strcpy(b,"7");
if(times == 3)
strcpy(c,"7");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"7");
if(times == 2)
strcat(b,"7");
if(times == 3)
strcat(c,"7");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_8)
{
if (first_input)
{
if(times == 1)
strcpy(a,"8");
if(times == 2)
strcpy(b,"8");
if(times == 3)
strcpy(c,"8");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"8");
if(times == 2)
strcat(b,"8");
if(times == 3)
strcat(c,"8");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_9)
{
if (first_input)
{
if(times == 1)
strcpy(a,"9");
if(times == 2)
strcpy(b,"9");
if(times == 3)
strcpy(c,"9");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"9");
if(times == 2)
strcat(b,"9");
if(times == 3)
strcat(c,"9");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
if (key==sk_0)
{
if (first_input)
{
if(times == 1)
strcpy(a,"0");
if(times == 2)
strcpy(b,"0");
if(times == 3)
strcpy(c,"0");
first_input = false;
current_size++;
}
else
{
if(max_size>=current_size)
{
current_size++;
if(times == 1)
strcat(a,"0");
if(times == 2)
strcat(b,"0");
if(times == 3)
strcat(c,"0");
}
}
if(times == 1)
printText(a,0,6);
if(times == 2)
printText(b,0,6);
if(times == 3)
printText(c,0,6);
delay(delay_time);
}
}
current_size = 0;
if (times!=3)
{
times++;
goto key_input;
}
while(!os_GetCSC());
}
/* 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);
}
/* Draw small text at the given X/Y location */
void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos)
{
os_FontSelect(0); // sets small font (1 == big, see docs)
os_FontDrawText(text, xpos, ypos);
}
I haven't had time to look at your code in depth, but my first guess would be that your strings aren't null-terminated. Almost always, strings in C should end with '\0', AKA the "null terminator" character which indicates the end of the string. Without that character, functions that use the string will read past the end of the character array and produce garbage.
Thanks, I solved this problem. So I guess you don’t have to look in-depth the code