Skip to main content

1-2

Quest: page 8


Experiment to find out what happens whe printf's argument string contains \c, where c is some character not listed above.


explanation:

  • try out all escape sequences there are here is a list of useful escape sequences:

    • \a -> audible or visual alert (if supported by terminal)
    • \n -> newline
      • add a newline
    • \b -> backspace
      • delete one char back useful when we want to delete some fixed chars
    • \f -> form feed
      • It skips to the start of the next page. (Applies mostly to terminals where the output device is a printer rather than a VDU.)
    • \r -> carriage return
      • move back the cursor the the start of the line and overwrite text. useful when loading something and display loading progress for instance.
    • \t -> horizontal tab
      • move the value one tab to the right
    • \v -> vertical tab
      • move the value one tab to the bottom and right (vertical)
    • \ -> add a backslash
    • \' -> add a single quote
    • \" -> add a double quote
    • \? -> question mark
    • \ooo -> octal number
    • \xhh -> hex number
    • \0 -> NULL character
      • this is used to find the end of something usually
all escape sequences
#include <stdio.h>
#include <stdlib.h>

int main() {
// audible
printf("Audible or visual alert. \a\n");
// newline
printf("HELLO \n");
// backspace
printf("HELLO\b backspace \n");
// form feed
printf("\fForm feed. \f\n");
// carriage return observe output
printf("printed-1.");
printf("\rprinted-2.");
printf("\n");
// horizontal tab sequence
printf("val1\tval2\n");
// vertical tab sequence
printf("val1\vval2\vval3\n");
// backslash
printf("slash\\slash\n");
// single and double quote
printf("\'single quote\' \"double quote\"\n");
// question mark
printf("\? \n");
// octal 112 = decimal 74 = ascii char J
printf("\112\n");
// hex 4a = 74 = decimal 74 = ascii char J
printf("\x4a \n");
return EXIT_SUCCESS;
}
output
Audible or visual alert.
HELLO
HELL backspace

Form feed.

printed-2.
val1 val2
val1
val2
val3
slash\slash
'single quote' "double quote"
?
J
J