4 /* print contents of array */
5 void print_array(char s
[])
8 for(i
= 0; i
< strlen(s
); i
++)
13 /* reverse contents of array in place */
14 void reverse_array(char s
[])
17 for(i
= 0, j
= strlen(s
)-1; i
< j
; i
++, j
--)
25 /* convert int n into chars in s[] - page 64*/
26 void itoa(int n
, char s
[])
30 if((sign
= n
) < 0) // record sign
31 n
= -n
; // reverse sign
33 do { // generates digits in reverse order
34 s
[i
++] = n
% 10 + '0'; // get next digit and load into array
35 } while ((n
/= 10) > 0); // delete each digit as we move along
42 /* recursive version of itoa - book has not covered pointers yet :( */
43 int itoa_rec(int n
, char s
[], int i
)
51 i
= itoa_rec(n
/10, s
,i
);
53 s
[i
++] = (n
% 10 + '0');
60 char s
[10]; // must have plenty of space here...