Home » Archimedes archive » Acorn User » AU 1994-10.adf » !Extras_Extras » CTutorial/c/Characters
CTutorial/c/Characters
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1994-10.adf » !Extras_Extras |
Filename: | CTutorial/c/Characters |
Read OK: | ✔ |
File size: | 065D bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* Characters, by David Matthewman. */ /* This program demonstrates escape codes for character */ /* variables in C. */ /* Type Return after each line has been displayed */ #include <stdio.h> main() { char c,dummy; printf("Type Return after each line to move to the next.\n"); c = '\a'; printf("\\a: the bell character:%c\n",c); gets(&dummy); c = '\b'; printf("\\b: the backspace:***%c%c%c\n",c,c,c); gets(&dummy); c = '\f'; printf("\\f: the form feed character:%c(odd with no printer)\n",c); gets(&dummy); c = '\n'; printf("\\n: the newline character:%cNext line...\n",c); gets(&dummy); c = '\r'; printf("\\r: the carriage return:%cNext line...\n",c); gets(&dummy); c = '\t'; printf("\\t: the horizontal tab%cto here.\n",c); gets(&dummy); c = '\v'; printf("\\v: the vertical tab%cto here.\n",c); gets(&dummy); c = '\\'; printf("\\\\: the backslash character:%c\n",c); gets(&dummy); c = '\?'; printf("\\\?: the question mark:%c\n",c); gets(&dummy); c = '\''; printf("\\\': the single quote:%c\n",c); gets(&dummy); c = '\"'; printf("\\\": the double quote:%c\n",c); gets(&dummy); c = '\041'; printf("\\000: octal character, 041 (decimal 33) is:%c\n",c); gets(&dummy); c = '\x41'; printf("\\xhh: hex character, x41 (decimal 65) is:%c\n",c); gets(&dummy); c = '\0'; printf("\\0: Null character:%c\n",c); /* Note that the so-called 'null character' may print as |@ (Ctrl-@, */ /* equivalent to ASCII zero) on Risc OS. */ gets(&dummy); return 0; }
00000000 2f 2a 20 43 68 61 72 61 63 74 65 72 73 2c 20 62 |/* Characters, b| 00000010 79 20 44 61 76 69 64 20 4d 61 74 74 68 65 77 6d |y David Matthewm| 00000020 61 6e 2e 20 20 20 20 20 20 20 20 20 20 20 20 20 |an. | 00000030 20 20 20 20 20 20 20 20 2a 2f 0a 2f 2a 20 54 68 | */./* Th| 00000040 69 73 20 70 72 6f 67 72 61 6d 20 64 65 6d 6f 6e |is program demon| 00000050 73 74 72 61 74 65 73 20 65 73 63 61 70 65 20 63 |strates escape c| 00000060 6f 64 65 73 20 66 6f 72 20 63 68 61 72 61 63 74 |odes for charact| 00000070 65 72 20 2a 2f 0a 2f 2a 20 76 61 72 69 61 62 6c |er */./* variabl| 00000080 65 73 20 69 6e 20 43 2e 20 20 20 20 20 20 20 20 |es in C. | 00000090 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000000a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f | */| 000000b0 0a 2f 2a 20 54 79 70 65 20 52 65 74 75 72 6e 20 |./* Type Return | 000000c0 61 66 74 65 72 20 65 61 63 68 20 6c 69 6e 65 20 |after each line | 000000d0 68 61 73 20 62 65 65 6e 20 64 69 73 70 6c 61 79 |has been display| 000000e0 65 64 20 20 20 20 20 20 20 2a 2f 0a 0a 23 69 6e |ed */..#in| 000000f0 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a |clude <stdio.h>.| 00000100 0a 6d 61 69 6e 28 29 0a 7b 20 63 68 61 72 20 63 |.main().{ char c| 00000110 2c 64 75 6d 6d 79 3b 0a 0a 20 20 70 72 69 6e 74 |,dummy;.. print| 00000120 66 28 22 54 79 70 65 20 52 65 74 75 72 6e 20 61 |f("Type Return a| 00000130 66 74 65 72 20 65 61 63 68 20 6c 69 6e 65 20 74 |fter each line t| 00000140 6f 20 6d 6f 76 65 20 74 6f 20 74 68 65 20 6e 65 |o move to the ne| 00000150 78 74 2e 5c 6e 22 29 3b 0a 20 20 63 20 3d 20 27 |xt.\n");. c = '| 00000160 5c 61 27 3b 0a 20 20 70 72 69 6e 74 66 28 22 5c |\a';. printf("\| 00000170 5c 61 3a 20 74 68 65 20 62 65 6c 6c 20 63 68 61 |\a: the bell cha| 00000180 72 61 63 74 65 72 3a 25 63 5c 6e 22 2c 63 29 3b |racter:%c\n",c);| 00000190 0a 20 20 67 65 74 73 28 26 64 75 6d 6d 79 29 3b |. gets(&dummy);| 000001a0 0a 20 20 63 20 3d 20 27 5c 62 27 3b 0a 20 20 70 |. c = '\b';. p| 000001b0 72 69 6e 74 66 28 22 5c 5c 62 3a 20 74 68 65 20 |rintf("\\b: the | 000001c0 62 61 63 6b 73 70 61 63 65 3a 2a 2a 2a 25 63 25 |backspace:***%c%| 000001d0 63 25 63 5c 6e 22 2c 63 2c 63 2c 63 29 3b 0a 20 |c%c\n",c,c,c);. | 000001e0 20 67 65 74 73 28 26 64 75 6d 6d 79 29 3b 0a 20 | gets(&dummy);. | 000001f0 20 63 20 3d 20 27 5c 66 27 3b 0a 20 20 70 72 69 | c = '\f';. pri| 00000200 6e 74 66 28 22 5c 5c 66 3a 20 74 68 65 20 66 6f |ntf("\\f: the fo| 00000210 72 6d 20 66 65 65 64 20 63 68 61 72 61 63 74 65 |rm feed characte| 00000220 72 3a 25 63 28 6f 64 64 20 77 69 74 68 20 6e 6f |r:%c(odd with no| 00000230 20 70 72 69 6e 74 65 72 29 5c 6e 22 2c 63 29 3b | printer)\n",c);| 00000240 0a 20 20 67 65 74 73 28 26 64 75 6d 6d 79 29 3b |. gets(&dummy);| 00000250 0a 20 20 63 20 3d 20 27 5c 6e 27 3b 0a 20 20 70 |. c = '\n';. p| 00000260 72 69 6e 74 66 28 22 5c 5c 6e 3a 20 74 68 65 20 |rintf("\\n: the | 00000270 6e 65 77 6c 69 6e 65 20 63 68 61 72 61 63 74 65 |newline characte| 00000280 72 3a 25 63 4e 65 78 74 20 6c 69 6e 65 2e 2e 2e |r:%cNext line...| 00000290 5c 6e 22 2c 63 29 3b 0a 20 20 67 65 74 73 28 26 |\n",c);. gets(&| 000002a0 64 75 6d 6d 79 29 3b 0a 20 20 63 20 3d 20 27 5c |dummy);. c = '\| 000002b0 72 27 3b 0a 20 20 70 72 69 6e 74 66 28 22 5c 5c |r';. printf("\\| 000002c0 72 3a 20 74 68 65 20 63 61 72 72 69 61 67 65 20 |r: the carriage | 000002d0 72 65 74 75 72 6e 3a 25 63 4e 65 78 74 20 6c 69 |return:%cNext li| 000002e0 6e 65 2e 2e 2e 5c 6e 22 2c 63 29 3b 0a 20 20 67 |ne...\n",c);. g| 000002f0 65 74 73 28 26 64 75 6d 6d 79 29 3b 0a 20 20 63 |ets(&dummy);. c| 00000300 20 3d 20 27 5c 74 27 3b 0a 20 20 70 72 69 6e 74 | = '\t';. print| 00000310 66 28 22 5c 5c 74 3a 20 74 68 65 20 68 6f 72 69 |f("\\t: the hori| 00000320 7a 6f 6e 74 61 6c 20 74 61 62 25 63 74 6f 20 68 |zontal tab%cto h| 00000330 65 72 65 2e 5c 6e 22 2c 63 29 3b 0a 20 20 67 65 |ere.\n",c);. ge| 00000340 74 73 28 26 64 75 6d 6d 79 29 3b 0a 20 20 63 20 |ts(&dummy);. c | 00000350 3d 20 27 5c 76 27 3b 0a 20 20 70 72 69 6e 74 66 |= '\v';. printf| 00000360 28 22 5c 5c 76 3a 20 74 68 65 20 76 65 72 74 69 |("\\v: the verti| 00000370 63 61 6c 20 74 61 62 25 63 74 6f 20 68 65 72 65 |cal tab%cto here| 00000380 2e 5c 6e 22 2c 63 29 3b 0a 20 20 67 65 74 73 28 |.\n",c);. gets(| 00000390 26 64 75 6d 6d 79 29 3b 0a 20 20 63 20 3d 20 27 |&dummy);. c = '| 000003a0 5c 5c 27 3b 0a 20 20 70 72 69 6e 74 66 28 22 5c |\\';. printf("\| 000003b0 5c 5c 5c 3a 20 74 68 65 20 62 61 63 6b 73 6c 61 |\\\: the backsla| 000003c0 73 68 20 63 68 61 72 61 63 74 65 72 3a 25 63 5c |sh character:%c\| 000003d0 6e 22 2c 63 29 3b 0a 20 20 67 65 74 73 28 26 64 |n",c);. gets(&d| 000003e0 75 6d 6d 79 29 3b 0a 20 20 63 20 3d 20 27 5c 3f |ummy);. c = '\?| 000003f0 27 3b 0a 20 20 70 72 69 6e 74 66 28 22 5c 5c 5c |';. printf("\\\| 00000400 3f 3a 20 74 68 65 20 71 75 65 73 74 69 6f 6e 20 |?: the question | 00000410 6d 61 72 6b 3a 25 63 5c 6e 22 2c 63 29 3b 0a 20 |mark:%c\n",c);. | 00000420 20 67 65 74 73 28 26 64 75 6d 6d 79 29 3b 0a 20 | gets(&dummy);. | 00000430 20 63 20 3d 20 27 5c 27 27 3b 0a 20 20 70 72 69 | c = '\'';. pri| 00000440 6e 74 66 28 22 5c 5c 5c 27 3a 20 74 68 65 20 73 |ntf("\\\': the s| 00000450 69 6e 67 6c 65 20 71 75 6f 74 65 3a 25 63 5c 6e |ingle quote:%c\n| 00000460 22 2c 63 29 3b 0a 20 20 67 65 74 73 28 26 64 75 |",c);. gets(&du| 00000470 6d 6d 79 29 3b 0a 20 20 63 20 3d 20 27 5c 22 27 |mmy);. c = '\"'| 00000480 3b 0a 20 20 70 72 69 6e 74 66 28 22 5c 5c 5c 22 |;. printf("\\\"| 00000490 3a 20 74 68 65 20 64 6f 75 62 6c 65 20 71 75 6f |: the double quo| 000004a0 74 65 3a 25 63 5c 6e 22 2c 63 29 3b 0a 20 20 67 |te:%c\n",c);. g| 000004b0 65 74 73 28 26 64 75 6d 6d 79 29 3b 0a 20 20 63 |ets(&dummy);. c| 000004c0 20 3d 20 27 5c 30 34 31 27 3b 0a 20 20 70 72 69 | = '\041';. pri| 000004d0 6e 74 66 28 22 5c 5c 30 30 30 3a 20 6f 63 74 61 |ntf("\\000: octa| 000004e0 6c 20 63 68 61 72 61 63 74 65 72 2c 20 30 34 31 |l character, 041| 000004f0 20 28 64 65 63 69 6d 61 6c 20 33 33 29 20 69 73 | (decimal 33) is| 00000500 3a 25 63 5c 6e 22 2c 63 29 3b 0a 20 20 67 65 74 |:%c\n",c);. get| 00000510 73 28 26 64 75 6d 6d 79 29 3b 0a 20 20 63 20 3d |s(&dummy);. c =| 00000520 20 27 5c 78 34 31 27 3b 0a 20 20 70 72 69 6e 74 | '\x41';. print| 00000530 66 28 22 5c 5c 78 68 68 3a 20 68 65 78 20 63 68 |f("\\xhh: hex ch| 00000540 61 72 61 63 74 65 72 2c 20 78 34 31 20 28 64 65 |aracter, x41 (de| 00000550 63 69 6d 61 6c 20 36 35 29 20 69 73 3a 25 63 5c |cimal 65) is:%c\| 00000560 6e 22 2c 63 29 3b 0a 20 20 67 65 74 73 28 26 64 |n",c);. gets(&d| 00000570 75 6d 6d 79 29 3b 0a 20 20 63 20 3d 20 27 5c 30 |ummy);. c = '\0| 00000580 27 3b 0a 20 20 70 72 69 6e 74 66 28 22 5c 5c 30 |';. printf("\\0| 00000590 3a 20 4e 75 6c 6c 20 63 68 61 72 61 63 74 65 72 |: Null character| 000005a0 3a 25 63 5c 6e 22 2c 63 29 3b 0a 0a 2f 2a 20 4e |:%c\n",c);../* N| 000005b0 6f 74 65 20 74 68 61 74 20 74 68 65 20 73 6f 2d |ote that the so-| 000005c0 63 61 6c 6c 65 64 20 27 6e 75 6c 6c 20 63 68 61 |called 'null cha| 000005d0 72 61 63 74 65 72 27 20 6d 61 79 20 70 72 69 6e |racter' may prin| 000005e0 74 20 61 73 20 7c 40 20 28 43 74 72 6c 2d 40 2c |t as |@ (Ctrl-@,| 000005f0 20 20 2a 2f 0a 2f 2a 20 65 71 75 69 76 61 6c 65 | */./* equivale| 00000600 6e 74 20 74 6f 20 41 53 43 49 49 20 7a 65 72 6f |nt to ASCII zero| 00000610 29 20 6f 6e 20 52 69 73 63 20 4f 53 2e 20 20 20 |) on Risc OS. | 00000620 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000630 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 0a 20 | */.. | 00000640 20 67 65 74 73 28 26 64 75 6d 6d 79 29 3b 0a 0a | gets(&dummy);..| 00000650 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d | return 0;.}| 0000065d