Skip to content

Commit 0f95bd9

Browse files
committed
more docs
1 parent 98f9ae3 commit 0f95bd9

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

conversions/int_to_string.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* @file
43
* @brief Convert a positive integer to string (non-standard function)
@@ -52,26 +51,26 @@ char *int_to_string(uint16_t value, char *dest, int base)
5251
static void test()
5352
{
5453
const int MAX_SIZE = 100;
55-
for (int i = 1; i <= 100; ++i)
56-
{
57-
char *str1 = (char *)calloc(sizeof(char), MAX_SIZE);
58-
char *str2 = (char *)calloc(sizeof(char), MAX_SIZE);
54+
char *str1 = (char *)calloc(sizeof(char), MAX_SIZE);
55+
char *str2 = (char *)calloc(sizeof(char), MAX_SIZE);
5956

57+
for (int i = 1; i <= 100; ++i) /* test 100 random numbers */
58+
{
6059
/* Generate value from 0 to 100 */
6160
int value = rand() % 100;
6261

6362
// assert(strcmp(itoa(value, str1, 2), int_to_string(value, str2, 2)) ==
6463
// 0);
65-
snprintf(str1, MAX_SIZE, "%o", value);
64+
snprintf(str1, MAX_SIZE, "%o", value); //* standard C - to octal */
6665
assert(strcmp(str1, int_to_string(value, str2, 8)) == 0);
67-
snprintf(str1, MAX_SIZE, "%d", value);
66+
snprintf(str1, MAX_SIZE, "%d", value); /* standard C - to decimal */
6867
assert(strcmp(str1, int_to_string(value, str2, 10)) == 0);
69-
snprintf(str1, MAX_SIZE, "%x", value);
68+
snprintf(str1, MAX_SIZE, "%x", value); /* standard C - to hexadecimal */
7069
assert(strcmp(str1, int_to_string(value, str2, 16)) == 0);
71-
72-
free(str1);
73-
free(str2);
7470
}
71+
72+
free(str1);
73+
free(str2);
7574
}
7675

7776
/** Driver Code */

0 commit comments

Comments
 (0)