printf format parameter contain undefined escape character

寵の児 提交于 2020-01-15 06:06:32

问题


#include <stdio.h>

int main()
{
   printf("Hello\c!\n");
   return 0;
}

Output : Helloc!

So , when \[some_undifined_symbol] appeared in printf 's format string, it just ignore the \ ?


回答1:


\c is not an escape sequence that is already defined, but it's better to avoid using it because it's reserved:

C99 §6.11.4 Character escape sequences

Lowercase letters as escape sequences are reserved for future standardization. Other characters may be used in extensions.




回答2:


You have the following escape sequences defined for c:

  • \' single quote
  • \" double quote
  • \\ backslash
  • \0 null character
  • \a audible bell
  • \b backspace
  • \f form feed - new page
  • \n line feed - new line
  • \r carriage return
  • \t horizontal tab
  • \v vertical tab
  • \nnn arbitrary octal value
  • \xnn arbitrary hexadecimal value


来源:https://stackoverflow.com/questions/18718787/printf-format-parameter-contain-undefined-escape-character

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