I have created a function that recognizes numbers and prints them as an int. However, when this function is applied to the main code, the controller is stopped due to lack of resources. I have never used a String type because I’ve been through resource shortage before using a String type.
I would like to change the return type to char, and not use sprintf and sscanf to further optimize this function.
I have some doubts that the controller is stopped due to lack of resources; but without seeing the full code it’s difficult to say.
To convert a sequence of ascii digits, you can use something like below. Not tested
uint8_t checkDigit(char getData[], uint8_t startLen, uint8_t endLen)
{
uint8_t k = 0;
for (int i = startLen ; i <= endLen; i++)
{
if (isDigit(getData[i]))
{
k = k * 10 + getData[i] - '0';
}
else
{
break;
}
}
return k;
}
PS 1
I’m not sure how you think that 65535 will fit in an uint8_t.
PS 2
I suspect that getData must be an array of pointers or aa muktidimensional array.
Thank you very much for your reply.
I’m sorry, I wrote the getData wrong values in the first place and the variable was wrong. Thank you for pointing out.
getData was { “6”, “5”, “5”, “3”, “2”, “T”, …};
I had to specify a certain range of digits, each with a character to make a number.
Based on what you advised, I modified the code and applied it.