By putting single quotes around a backslash followed by either x or X followed

By putting single quotes around a backslash followed

This preview shows page 6 - 8 out of 9 pages.

By putting single quotes around a backslash followed by either x or X followed by the hexadecimal value of the code of the character. For instance, upper case C, whose ascii code has a decimal value of 67, can be represented by one of ’C’ 67 ’\103’ ’\x43’ ’\X43’ The first representation is usually much preferable. COMP9021 (Principles of Programming) Notes 5.0: Arithmetic types, constants, printf() 2014 session 1 23 / 36 Constants that represent characters (2) For some characters, an escape sequence rather than the character itself can be put between single quotes: \a for BEL ( a lert, which can be an auditive or visual signal) \b for BS ( b ackspace) \f for FF ( f ormfeed, which advances to start of next page) \n for LF ( n ew line, which moves to beginning of next line) \r for CR (carriage r eturn, which moves to beginning of current line) \v for VT ( v ertical tab, which moves to next vertical tab position) \’ for the single quote \\ for the backslash The horizontal tab can be inserted directly between single quotes (in Emacs, by typing \C-q and then hitting the tab key), or one can use the escape sequence \t . COMP9021 (Principles of Programming) Notes 5.0: Arithmetic types, constants, printf() 2014 session 1 24 / 36
Image of page 6

Subscribe to view the full document.

An example of use of escape sequences The program salary.c illustrates the use of escape sequences, though the demonstration is more convincing when the program is run from the command line rather than from within Emacs. . . The escape sequence \b occurs in the string constant Enter your \"year\ly\" salary: $______\b\b\b\b\b\b which, as any string constant, is delimited by a pair of double quotes. The string constant contains two occurrences of double quotes that, in order not to be confused with a double quote that delimits a string constant, are escaped. A character that taken individually, does not need to be escaped, can be escaped either with no useful effect, as the escaped l in year\ly , or with a useful effect as the escaped double quotes around year\ly , provided of course that the escaped character is not one of the special escape sequences (as would be the case if the occurrence of a within year\ly was escaped. . . ). COMP9021 (Principles of Programming) Notes 5.0: Arithmetic types, constants, printf() 2014 session 1 25 / 36 Functions to manipulate characters (1) The standard library provides two useful functions to process characters. getchar() is a function that takes no argument; each time it is called it reads the next character from the text stream associated with the standard input (by default the keyboard) and returns the value of type int that represents that character. putchar() is a function that takes one integer as (unique) argument; it prints the character represented by the value of its argument on the text stream associated with the standard output (by default the screen). To process input stored in a file file , the contents of the file can be redirected to standard input with the < redirection operator: the program can then be run by typing a.out < file from the command line or by typing r < file from within Emacs.
Image of page 7
Image of page 8
  • Fall '19
  • 11

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes