Added intToString(int32_t input, char* output) function

This commit is contained in:
Kristian Sloth Lauszus 2013-02-20 22:25:33 +01:00
parent 09c5b6c5a3
commit 734f004671
2 changed files with 16 additions and 12 deletions

21
SPP.cpp
View file

@ -809,26 +809,23 @@ void SPP::printNumberln(uint32_t n) {
void SPP::printNumber(int32_t n) {
char output[12];
if(n < 0) {
char buf[11];
intToString(n*-1,buf);
strcpy(output,"-");
strcat(output,buf);
} else
intToString(n,output);
intToString(n,output);
print(output);
}
void SPP::printNumberln(int32_t n) {
char output[14];
if(n < 0) {
intToString(n,output);
strcat(output,"\r\n");
print(output);
}
void SPP::intToString(int32_t input, char* output) {
if(input < 0) {
char buf[11];
intToString(n*-1,buf);
intToString((uint32_t)(input*-1),buf);
strcpy(output,"-");
strcat(output,buf);
} else
intToString(n,output);
strcat(output,"\r\n");
print(output);
intToString((uint32_t)input,output);
}
void SPP::intToString(uint32_t input, char* output) {
uint32_t temp = input;

7
SPP.h
View file

@ -236,6 +236,13 @@ public:
* @param n Signed integer to send.
*/
void printNumberln(int32_t n);
/**
* Helper function to convert from an unsigned integer to a string.
* @param input Unsigned integer to convert.
* @param output Output buffer.
*/
void intToString(int32_t input, char* output);
/**
* Helper function to convert from a signed integer to a string.
* @param input Signed integer to convert.