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

泪湿孤枕 提交于 2019-12-04 09:37:11

问题


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

Actually, rather than focusing on the problem and the line of codes, I want to know about the difference between %ul and %lu. Maybe I could figure out what's wrong.

Searching doesn't give me something useful (except that "they are different").

Any explanation or link/reference is appreciated.


回答1:


%lu is correct, while %ul is incorrect.

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

u is a specifier meaning "unsigned decimal integer".

l is a length modifier meaning "long".

The length modifier should go before the conversion specifier, which means %lu is correct.



来源:https://stackoverflow.com/questions/23852073/whats-the-difference-between-ul-and-lu-c-format-specifiers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!