What is the difference between% ul and% lu C format specifiers?

In the C Primer Plus example, the author used the %ul format specifier (for both scanf and printf) for unsigned long . When I try to generalize the problem, it seems that %ul doing something wrong on my computer. But using %lu solved the problem.

Actually, instead of focusing on the problem and the line of codes, I want to know about the difference between %ul and %lu . Maybe I can understand what is wrong.

The search does not give me anything useful (except that "they are different").

Any explanation or link / link is appreciated.

+6
source share
1 answer

%lu correct, and %ul invalid.

A printf format specifier follows the form %[flags][width][.precision][length]specifier .

u is a qualifier meaning "unsigned decimal integer".

l is a length modifier meaning "long".

The length modifier must go before the conversion specifier, which means %lu .

+25
source

Source: https://habr.com/ru/post/969824/


All Articles