The first problem (the leading 0 being dropped), means that you need to handle that bit of data, as a string, rather than just converting it to an int, right away.
perhaps itoa(): (from Borland's help file)
itoa Converts an integer to a string.
Syntax:
char *itoa(int value, char *string, int radix);
Prototype in:
stdlib.h
Remarks:
itoa converts value to a null-terminated
string and stores the result in string. With
itoa, value is an integer.
radix specifies the base to be used in
converting value. radix must be between 2 and
36, inclusive.
If value is negative and radix is 10, the
first character of string is the minus sign
(-).
The space allocated for string must be large
enough to hold the returned string, including
the terminating null character (\0). itoa can
return up to 17 bytes.
Return Value:
Returns a pointer to the target string.
Portability:
itoa is unique to DOS (works in text console on Windows)
See Also:
ltoa ultoa
Example:
Code:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int number = 12345;
char string[25];
itoa(number, string, 10);
printf("integer = %d string = %s\n", number, string);
return 0;
}