[prev in list] [next in list] [prev in thread] [next in thread]
List: suse-programming-e
Subject: Re: [suse-programming-e] warning: flag `0' used with type `s'
From: Peter Onion <Peter.Onion () btinternet ! com>
Date: 2005-07-09 10:10:55
Message-ID: 1120903855.5876.45.camel () HP ! RoomLan
[Download RAW message or body]
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
--
To unsubscribe, email: suse-programming-e-unsubscribe@suse.com
For additional commands, email: suse-programming-e-help@suse.com
Archives can be found at: http://lists.suse.com/archive/suse-programming-e
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic