Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

\c escape sequence listed in man but unkown in C

I'm currently studying C, if this question seems an easy one or a newbie ones, then you know why.

Reading the man page for printf I found \c listed as an escape sequence. Its description is

produce no further output

I've never seen and heard about \c prior to this moment. So I decided to try it out in a simple hello world program :

printf("\nHello World\n\n\c");

As a result, gcc gives me this warning :

warning: unknown escape sequence: '\c' [enabled by default]

This sounds kind of odd for me, so I went trough it further investigating : I went to Wikipedia and \c wasn't listed as an escape sequence... Hence I tried searching around the web, and here on stack overflow. I've found very few references to \c (actually two) as discussed in this topic and this one (I think that the latter isn't really related to C but it seems that we are talking about "the same \c", reading the description given). Could somebody help me to understand this thing?

like image 424
Claudio Cortese Avatar asked Jan 20 '16 19:01

Claudio Cortese


People also ask

What is unknown escape sequence in C?

Kabir Patel wrote: > warning: unknown escape sequence '\)' Backslash is used as an escaping character for C strings; if you'd like to include a character that you wouldn't normally be able to represent in a text file then you can use an escape code for it, for example: \t tab (ASCII 9) \n newline (ASCII 10) \r carriage ...

What is the meaning of '\ n escape sequence?

For example, \n is an escape sequence that denotes a newline character.

How many escape sequences are there in C?

There are 15 types of escape sequence in C to achieve various purposes.


1 Answers

You are not reading the correct man page. What you are looking at is: man 1 printf, which is about the shell command printf, not the C standard function printf.

Use:

 man 3 printf

to read about the C library function. \c is not in C and hence, it's not recognized by printf(3).

The printf(1) you are looking at does work as documented.

$ /usr/bin/printf "ABC\chi"

produces:

ABC

Note that the Linux man pages in general may also have additional non-standard extensions (specific to Linux or glibc) and POSIX extensions etc. Non-standard extensions are usually documented as such but easy to miss. So if you are looking for what C standard says then you should look at the C standard. Here's an online draft.

If you are wondering what the number passed to man is, it's the section number. 3 corresponds to library function. You can find details with: man man. Here's summary of the sections:

   1   Executable programs or shell commands
   2   System calls (functions provided by the kernel)
   3   Library calls (functions within program libraries)
   4   Special files (usually found in /dev)
   5   File formats and conventions eg /etc/passwd
   6   Games
   7   Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
   8   System administration commands (usually only for root)
   9   Kernel routines [Non standard]
like image 185
P.P Avatar answered Oct 01 '22 14:10

P.P