Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在寻找一个体面的单行 c 语句来保持字符之间'0'和'9'递增
'0'
'9'
我现在拥有的是这样的:
char c; ... c = (((c % 48 ) + 1) % 10) + 48;
有没有更好的方法来做这个?
使用'0'而不是硬编码其 ASCII 值。我也喜欢c - '0'比c % '0'; 它与+ '0'更好的匹配。
c - '0'
c % '0'
+ '0'
c = (c - '0' + 1) % 10 + '0'