[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Escaping %s



On Tue, 25 Jan 2005 11:29:19 +0200, ocl writes:
> printf("date --date=\"Mon Jan 10 08:00:20 CET 2005\" + \"%s\"\n");

On Tue, Jan 25, 2005 at 10:33:37AM +0100, Robert Waldner wrote:
> In printf syntax, you should use %% to get a single % displayed.

alternatively, try:

printf("%s", "date --date=\"Mon Jan 10 08:00:20 CET 2005\" + \"%s\"\n");

This way you can put any string you like in the second argument and
printf won't mess with it.

It's dangerous to pass arbitrary strings to the first argument of
printf, do it like my example above instead.

Or you could write a wrapper function, like:

int print(const char *s) {
	return printf("%s", s);
}

have fun!



Reply to: