6 /* print contents of array */
7 void print_array(char s
[])
10 for(i
= 0; i
< strlen(s
); i
++)
15 /* print contents of array */
16 void print_sparse_array(char s
[][MAXLEN
])
19 for(i
= 0; i
< MAXLINES
; i
++)
22 for(j
= 0; j
< MAXLEN
; j
++)
24 if(s
[i
][j
] != '\0') { found
++; }
29 for(j
= 0; j
< MAXLEN
; j
++)
30 printf("%c", s
[i
][j
]);
37 /* reverse contents of array in place */
38 void reverse(char s
[])
41 for(i
= 0, j
= strlen(s
)-1; i
< j
; i
++, j
--)
49 /* convert integer to another base and store result in array of char */
50 int itob(int n
, char s
[], int b
)
54 //create string of digits used to represent chars
55 char base_chars
[] = { "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" };
57 //check that base is neither too high nor too small
60 printf("Base must be between 2 and %d.\n", (int)strlen(base_chars
)-1);
64 if(b
> strlen(base_chars
)-1)
66 printf("Base must be %d or less.\n", (int)strlen(base_chars
)-1);
70 // remove sign from number
71 if(n
< 0) { n
= -n
; sign
= 1; }
74 // increment s array and store in that location the modulus of the number -vs- the base
75 // while number divided by base is larger than 0
78 s
[i
++] = base_chars
[n
% b
];
79 } while ((n
/= b
) > 0);
81 // add sign from above
82 if(sign
== '1') { s
[++i
] = '-'; }