|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
Re: % stdout?
From: Reyk Floeter (reyk
openbsd.org)
Date: Thu Nov 09 2006 - 11:17:00 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Nov 09, 2006 at 11:59:12AM -0500, Jason Dixon wrote:
> > I have problems to print '%' in stdout... Suppose code below:
> >
> > #include <stdio.h>
> >
> > main() {
> > char foo[] = "bar=30%\n";
> > fprintf(stdout, bar);
> > }
> >
> > OpenBSD returns : bar=30
> > Linux returns : bar=30%
> >
> > How can I solve this? Thanks,
>
> $ cat foo.c
> #include <stdio.h>
>
> main() {
> char foo[] = "bar=30%%\n";
> fprintf(stdout, foo);
heh, you found the bug. i just wanted to bet that the code would not
run under linux...
> }
> $ gcc foo.c -o foo
> $ ./foo
> bar=30%
>
you should also completely avoid the format string in this case.
printf("%s", foo);
reyk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]