Skip to content

Instantly share code, notes, and snippets.

@GavukaAlexandr
Created July 28, 2018 21:55
Show Gist options
  • Save GavukaAlexandr/65f5817e84b0774fe34b707c6c6c087c to your computer and use it in GitHub Desktop.
Save GavukaAlexandr/65f5817e84b0774fe34b707c6c6c087c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define NUMBER_OF_DIGITS 16 /* space for NUMBER_OF_DIGITS + '\0' */
void uitoa(unsigned int value, char* string, int radix)
{
unsigned char index, i;
index = NUMBER_OF_DIGITS;
i = 0;
do {
string[--index] = '0' + (value % radix);
if ( string[index] > '9') string[index] += 'A' - ':'; /* continue with A, B,.. */
value /= radix;
} while (value != 0);
do {
string[i++] = string[index++];
} while ( index < NUMBER_OF_DIGITS );
string[i] = 0; /* string terminator */
}
void itoa(int value, char* string, int radix)
{
if (value < 0 && radix == 10) {
*string++ = '-';
uitoa(-value, string, radix);
}
else {
uitoa(value, string, radix);
}
}
int main()
{
char TxBuffer1[5] ="1 123";
// printf(TxBuffer1);
char* command;
for(int i = 0; i < sizeof(TxBuffer1); i++)
{
itoa (i, command, 10);
printf(command);
// if (i == 0) {
// printf(TxBuffer1[i+1]);
// command = TxBuffer1[i+1];
// }
}
// printf(command);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment