Lidong Guo
Lidong Guo

Reputation: 2857

printf format parameter contain undefined escape character

#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 \ ?

Upvotes: 2

Views: 760

Answers (2)

Paul Evans
Paul Evans

Reputation: 27567

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

Upvotes: 1

Yu Hao
Yu Hao

Reputation: 122373

\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.

Upvotes: 4

Related Questions