On Fri, 2005-07-08 at 17:28 -0300, Martin Llanos wrote:
I have a problem when compiling with GCC - Linux I obtain result ==> szValor:[ 34] (GCC 2.95 > - Linux) when I want to obtain ==> szValor:[00034] (xlC - AIX & MSVC) An example detail : ==============
1) SOURCE: #include "stdio.h" #include "stdlib.h" #include "string.h"
int main() { char szValor[44]; sprintf(szValor, "34"); printf("szValor:[%05s]\n", szValor); return (0); }
That won't do what you want.... try this int main() { char szValor[44]; sprintf(szValor, "%05d",34); printf("szValor:[%s]\n", szValor); return (0); } or even int main() { int szValor; szValor = 34; printf("szValor:[%05d]\n", szValor); return (0); } You need to specify the number of digits when you convert the integer 34 into a string. You can't add zeros to the start of a string using "%05s". Peter