OSEC

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: Matthew Closson (mattscrapshells.com)
Date: Thu Nov 09 2006 - 11:19:40 CST


On Thu, 9 Nov 2006, Cassio B. Caporal wrote:

> Hey,
>
> 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,

Use the format specifier with fprintf:

#include <stdio.h>

int main()
{
   char foo[] = "bar=30%\n";
   fprintf(stdout, "%s", foo);
}

cc test.c
./a.out
bar=30%

                 -Matt-