Asked  7 Months ago    Answers:  5   Viewed   39 times

How do you escape the % sign when using printf in C?

printf("hello%"); /* not like this */



You can escape it by posting a double '%' like this: %%

Using your example:


Escaping the '%' sign is only for printf. If you do:

char a[5];
strcpy(a, "%%");
printf("This is a's value: %sn", a);

It will print: This is a's value: %%

Tuesday, June 1, 2021
answered 7 Months ago

Moreover, Please refer to load(Reader reader) method from Property class on javadoc

In load(Reader reader) method documentation it says

The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped '=', ':', or white space character other than a line terminator. All of these key termination characters may be included in the key by escaping them with a preceding backslash character; for example,


would be the two-character key ":=". Line terminator characters can be included using r and n escape sequences. Any white space after the key is skipped; if the first non-white space character after the key is '=' or ':', then it is ignored and any white space characters after it are also skipped. All remaining characters on the line become part of the associated element string; if there are no remaining characters, the element is the empty string "". Once the raw character sequences constituting the key and element are identified, escape processing is performed as described above.

Hope that helps.

Thursday, June 3, 2021
answered 6 Months ago

It adds padding to the left. Very useful for remembering the various string formatting patterns is the following cheat sheet:

.NET String.Format Cheat Sheet

Positive values add padding to the left, negative add padding to the right

Sample                                 Generates
String.Format("[{0, 10}]", "Foo");     [???????Foo]
String.Format("[{0, 5}]", "Foo");      [??Foo]
String.Format("[{0, -5}]", "Foo");     [Foo??]
String.Format("[{0, -10}]", "Foo");    [Foo???????]
Tuesday, June 29, 2021
answered 6 Months ago

Your problem is that you have to change:




Or you could use ASCII code and write:

printf("%c", 37);


Monday, July 19, 2021
answered 5 Months ago

Somewhat shorter, using Custom TimeSpan Format Strings:

private string FormatTimeSpan(TimeSpan time)
    return ((time < TimeSpan.Zero) ? "-" : "") + time.ToString(@"mm:ss");
Saturday, October 9, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :