On Wed, Jun 11, 2008 at 10:30 AM, Nadav Har'El <[EMAIL PROTECTED]>
wrote:

> On Wed, Jun 11, 2008, Dan Bar Dov wrote about "Help with printf":
> >...
> > But if I put the format in a variable (as opposed to a string literal), I
> > find that
> > escape processing does not occur.
> >...
> > and running (# is the prompt)
> > # ./test "%s flowers\n" 7
> >
> > give the output
> > 7 flowers\n#
>
> What you call "escape processing", i.e., the conversion of the two
> characters
> "\n" into one newline character (ASCII code 10), isn't done by the printf
> library function - rather it is done by the C compiler!
> When the C compiler sees the character \ followed by n inside a string
> constant, it translates it into a newline character.


That explains it.


>
> The shell does not normally do this translation, which is why your "test"
> program gets the characters \ and n, not a newline.


I'm not using it from shell, that was just an example. I need to read
format strings from file
and use them to print stuff like error  reports (the error includes only
parameters, and the format string comes from a file.


>
> There are several ways you can fix this problem. The most obvious one is
> to parse the string in the C code, and do the replacement of \n into a


Is there a library function that does the "conversion" for me?

Thanks

Reply via email to