c - printf中lc和c/ls和s的区别

标签 c printf stdio

printf()函数中的lc(C)和c/ls(S)和s有什么区别?为什么ls(S)转换返回-1?

例子:

printf("%C", 'ͳʹ); // -1
printf("%c", 'ͳʹ); // PRINT
printf("%S", "ͳ ans T"); // -1
printf("%s", "ͳ and T"); // PRINT

在苹果机上..

最佳答案

来自手册页:

l

(ell) [...] or a following c conversion corresponds to a wint_t argument, or a following s conversion corresponds to a pointer to wchar_t argument.

所以变化是预期的类型:

  • %c - int 内部转换为 unsigned char
  • %lc - wint_t
  • %s - 指向以零结尾的 char
  • 数组的指针
  • %ls - 指向 wchar_t
  • 的零终止数组的指针

printf() 的负返回值,例如 -1 表示发生了错误。很难进一步确定,因为您没有显示任何代码。

关于c - printf中lc和c/ls和s的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37587777/

相关文章:

c - getch() 和 getchar() 有什么区别?

c - 我怎样才能捕获输出?

c - 在同一行中打印并在 C 中暂停

c - printf ("%f",x) ok, printf ("%F",x) 错误格式参数太多

C - 从文件中读取(非常简单)

c - 即使添加了 #include <stdio.h> 也隐式声明了 popen

c while循环入口

c - waitpid(pid, status, options) 并不总是设置状态

c - 三元运算符交互的多个部分

c - 理解 C 双格式化程序占位符