home *** CD-ROM | disk | FTP | other *** search
/ Sams Teach Yourself C in 21 Days (6th Edition) / STYC216E.ISO / mac / Examples / Day17 / getint.c < prev    next >
MacBinary  |  2002-05-18  |  1.9 KB  |  [TEXT/LMAN]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: MacBinary (archive/macBinary).

ConfidenceProgramDetectionMatch TypeSupport
66% dexvert Compact Compressed (Unix) (archive/compact) ext Supported
10% dexvert MacBinary (archive/macBinary) fallback Supported
1% dexvert Text File (text/txt) fallback Supported
100% file MacBinary II, Sat May 18 22:59:38 2002, modified Sat May 18 22:59:38 2002, creator 'LMAN', type ASCII, 1394 bytes "getint.c" , at 0x5f2 286 bytes resource default (weak)
99% file data default
74% TrID Macintosh plain text (MacBinary) default
25% TrID MacBinary 2 default (weak)
100% siegfried fmt/1762 MacBinary (II) default
100% lsar MacBinary default


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[LMAN]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 08 67 65 74 69 6e 74 | 2e 63 00 00 00 00 00 00 |..getint|.c......|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 4c 4d 41 | 4e 00 00 ff ff ff ff 00 |.TEXTLMA|N.......|
|00000050| 00 00 00 00 00 05 72 00 | 00 01 1e b9 0c c5 9a b9 |......r.|........|
|00000060| 0c c5 9a 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 a8 35 00 00 |........|.....5..|
|00000080| 2f 2a 20 55 73 69 6e 67 | 20 63 68 61 72 61 63 74 |/* Using| charact|
|00000090| 65 72 20 74 65 73 74 20 | 6d 61 63 72 6f 73 20 74 |er test |macros t|
|000000a0| 6f 20 63 72 65 61 74 65 | 20 61 6e 20 69 6e 74 65 |o create| an inte|
|000000b0| 67 65 72 20 2a 2f 0d 0a | 2f 2a 20 69 6e 70 75 74 |ger */..|/* input|
|000000c0| 20 66 75 6e 63 74 69 6f | 6e 2e 20 2a 2f 0d 0a 0d | functio|n. */...|
|000000d0| 0a 23 69 6e 63 6c 75 64 | 65 20 3c 73 74 64 69 6f |.#includ|e <stdio|
|000000e0| 2e 68 3e 0d 0a 23 69 6e | 63 6c 75 64 65 20 3c 63 |.h>..#in|clude <c|
|000000f0| 74 79 70 65 2e 68 3e 0d | 0a 0d 0a 69 6e 74 20 67 |type.h>.|...int g|
|00000100| 65 74 5f 69 6e 74 28 76 | 6f 69 64 29 3b 0d 0a 0d |et_int(v|oid);...|
|00000110| 0a 69 6e 74 20 6d 61 69 | 6e 28 20 76 6f 69 64 20 |.int mai|n( void |
|00000120| 29 0d 0a 7b 0d 0a 20 20 | 20 20 69 6e 74 20 78 3b |)..{.. | int x;|
|00000130| 0d 0a 20 20 20 20 78 20 | 3d 20 20 67 65 74 5f 69 |.. x |= get_i|
|00000140| 6e 74 28 29 3b 0d 0a 0d | 0a 20 20 20 20 70 72 69 |nt();...|. pri|
|00000150| 6e 74 66 28 22 59 6f 75 | 20 65 6e 74 65 72 65 64 |ntf("You| entered|
|00000160| 20 25 64 2e 5c 6e 22 2c | 20 78 29 3b 0d 0a 7d 0d | %d.\n",| x);..}.|
|00000170| 0a 0d 0a 69 6e 74 20 67 | 65 74 5f 69 6e 74 28 76 |...int g|et_int(v|
|00000180| 6f 69 64 29 0d 0a 7b 0d | 0a 20 20 20 20 69 6e 74 |oid)..{.|. int|
|00000190| 20 63 68 2c 20 69 2c 20 | 73 69 67 6e 20 3d 20 31 | ch, i, |sign = 1|
|000001a0| 3b 0d 0a 0d 0a 20 20 20 | 20 2f 2a 20 53 6b 69 70 |;.... | /* Skip|
|000001b0| 20 6f 76 65 72 20 61 6e | 79 20 6c 65 61 64 69 6e | over an|y leadin|
|000001c0| 67 20 77 68 69 74 65 20 | 73 70 61 63 65 2e 20 2a |g white |space. *|
|000001d0| 2f 0d 0a 0d 0a 20 20 20 | 20 77 68 69 6c 65 20 28 |/.... | while (|
|000001e0| 20 69 73 73 70 61 63 65 | 28 63 68 20 3d 20 67 65 | isspace|(ch = ge|
|000001f0| 74 63 68 61 72 28 29 29 | 20 29 0d 0a 20 20 20 20 |tchar())| ).. |
|00000200| 20 20 20 20 3b 0d 0a 0d | 0a 20 20 20 20 2f 2a 20 | ;...|. /* |
|00000210| 49 66 20 74 68 65 20 66 | 69 72 73 74 20 63 68 61 |If the f|irst cha|
|00000220| 72 61 63 74 65 72 20 69 | 73 20 6e 6f 6e 6e 75 6d |racter i|s nonnum|
|00000230| 65 72 69 63 2c 20 75 6e | 67 65 74 20 2a 2f 0d 0a |eric, un|get */..|
|00000240| 20 20 20 20 2f 2a 20 74 | 68 65 20 63 68 61 72 61 | /* t|he chara|
|00000250| 63 74 65 72 20 61 6e 64 | 20 72 65 74 75 72 6e 20 |cter and| return |
|00000260| 30 2e 20 2a 2f 0d 0a 0d | 0a 20 20 20 20 69 66 20 |0. */...|. if |
|00000270| 28 63 68 20 21 3d 20 27 | 2d 27 20 26 26 20 63 68 |(ch != '|-' && ch|
|00000280| 20 21 3d 20 27 2b 27 20 | 26 26 20 21 69 73 64 69 | != '+' |&& !isdi|
|00000290| 67 69 74 28 63 68 29 20 | 26 26 20 63 68 20 21 3d |git(ch) |&& ch !=|
|000002a0| 20 45 4f 46 29 0d 0a 20 | 20 20 20 7b 0d 0a 20 20 | EOF).. | {.. |
|000002b0| 20 20 20 20 20 20 75 6e | 67 65 74 63 28 63 68 2c | un|getc(ch,|
|000002c0| 20 73 74 64 69 6e 29 3b | 0d 0a 20 20 20 20 20 20 | stdin);|.. |
|000002d0| 20 20 72 65 74 75 72 6e | 20 30 3b 0d 0a 20 20 20 | return| 0;.. |
|000002e0| 20 7d 0d 0a 0d 0a 20 20 | 20 20 2f 2a 20 49 66 20 | }.... | /* If |
|000002f0| 74 68 65 20 66 69 72 73 | 74 20 63 68 61 72 61 63 |the firs|t charac|
|00000300| 74 65 72 20 69 73 20 61 | 20 6d 69 6e 75 73 20 73 |ter is a| minus s|
|00000310| 69 67 6e 2c 20 73 65 74 | 20 2a 2f 0d 0a 20 20 20 |ign, set| */.. |
|00000320| 20 2f 2a 20 73 69 67 6e | 20 61 63 63 6f 72 64 69 | /* sign| accordi|
|00000330| 6e 67 6c 79 2e 20 2a 2f | 0d 0a 0d 0a 20 20 20 20 |ngly. */|.... |
|00000340| 69 66 20 28 63 68 20 3d | 3d 20 27 2d 27 29 0d 0a |if (ch =|= '-')..|
|00000350| 20 20 20 20 20 20 20 20 | 73 69 67 6e 20 3d 20 2d | |sign = -|
|00000360| 31 3b 0d 0a 0d 0a 20 20 | 20 20 2f 2a 20 49 66 20 |1;.... | /* If |
|00000370| 74 68 65 20 66 69 72 73 | 74 20 63 68 61 72 61 63 |the firs|t charac|
|00000380| 74 65 72 20 77 61 73 20 | 61 20 70 6c 75 73 20 6f |ter was |a plus o|
|00000390| 72 20 6d 69 6e 75 73 20 | 73 69 67 6e 2c 20 2a 2f |r minus |sign, */|
|000003a0| 0d 0a 20 20 20 20 2f 2a | 20 67 65 74 20 74 68 65 |.. /*| get the|
|000003b0| 20 6e 65 78 74 20 63 68 | 61 72 61 63 74 65 72 2e | next ch|aracter.|
|000003c0| 20 2a 2f 0d 0a 0d 0a 20 | 20 20 20 69 66 20 28 63 | */.... | if (c|
|000003d0| 68 20 3d 3d 20 27 2b 27 | 20 7c 7c 20 63 68 20 3d |h == '+'| || ch =|
|000003e0| 3d 20 27 2d 27 29 0d 0a | 20 20 20 20 20 20 20 20 |= '-')..| |
|000003f0| 63 68 20 3d 20 67 65 74 | 63 68 61 72 28 29 3b 0d |ch = get|char();.|
|00000400| 0a 0d 0a 20 20 20 20 2f | 2a 20 52 65 61 64 20 63 |... /|* Read c|
|00000410| 68 61 72 61 63 74 65 72 | 73 20 75 6e 74 69 6c 20 |haracter|s until |
|00000420| 61 20 6e 6f 6e 64 69 67 | 69 74 20 69 73 20 69 6e |a nondig|it is in|
|00000430| 70 75 74 2e 20 41 73 73 | 69 67 6e 20 2a 2f 0d 0a |put. Ass|ign */..|
|00000440| 20 20 20 20 2f 2a 20 76 | 61 6c 75 65 73 2c 20 6d | /* v|alues, m|
|00000450| 75 6c 74 69 70 6c 69 65 | 64 20 62 79 20 70 72 6f |ultiplie|d by pro|
|00000460| 70 65 72 20 70 6f 77 65 | 72 20 6f 66 20 31 30 2c |per powe|r of 10,|
|00000470| 20 74 6f 20 69 2e 20 2a | 2f 0d 0a 0d 0a 20 20 20 | to i. *|/.... |
|00000480| 20 66 6f 72 20 28 69 20 | 3d 20 30 3b 20 69 73 64 | for (i |= 0; isd|
|00000490| 69 67 69 74 28 63 68 29 | 3b 20 63 68 20 3d 20 67 |igit(ch)|; ch = g|
|000004a0| 65 74 63 68 61 72 28 29 | 20 29 0d 0a 20 20 20 20 |etchar()| ).. |
|000004b0| 20 20 20 20 69 20 3d 20 | 31 30 20 2a 20 69 20 2b | i = |10 * i +|
|000004c0| 20 28 63 68 20 2d 20 27 | 30 27 29 3b 0d 0a 0d 0a | (ch - '|0');....|
|000004d0| 20 20 20 20 2f 2a 20 4d | 61 6b 65 20 72 65 73 75 | /* M|ake resu|
|000004e0| 6c 74 20 6e 65 67 61 74 | 69 76 65 20 69 66 20 73 |lt negat|ive if s|
|000004f0| 69 67 6e 20 69 73 20 6e | 65 67 61 74 69 76 65 2e |ign is n|egative.|
|00000500| 20 2a 2f 0d 0a 0d 0a 20 | 20 20 20 69 20 2a 3d 20 | */.... | i *= |
|00000510| 73 69 67 6e 3b 0d 0a 0d | 0a 20 20 20 20 2f 2a 20 |sign;...|. /* |
|00000520| 49 66 20 45 4f 46 20 77 | 61 73 20 6e 6f 74 20 65 |If EOF w|as not e|
|00000530| 6e 63 6f 75 6e 74 65 72 | 65 64 2c 20 61 20 6e 6f |ncounter|ed, a no|
|00000540| 6e 64 69 67 69 74 20 63 | 68 61 72 61 63 74 65 72 |ndigit c|haracter|
|00000550| 20 2a 2f 0d 0a 20 20 20 | 20 2f 2a 20 6d 75 73 74 | */.. | /* must|
|00000560| 20 68 61 76 65 20 62 65 | 65 6e 20 72 65 61 64 20 | have be|en read |
|00000570| 69 6e 2c 20 73 6f 20 75 | 6e 67 65 74 20 69 74 2e |in, so u|nget it.|
|00000580| 20 2a 2f 0d 0a 0d 0a 20 | 20 20 20 69 66 20 28 63 | */.... | if (c|
|00000590| 68 20 21 3d 20 45 4f 46 | 29 0d 0a 20 20 20 20 20 |h != EOF|).. |
|000005a0| 20 20 20 75 6e 67 65 74 | 63 28 63 68 2c 20 73 74 | unget|c(ch, st|
|000005b0| 64 69 6e 29 3b 0d 0a 0d | 0a 20 20 20 20 2f 2a 20 |din);...|. /* |
|000005c0| 52 65 74 75 72 6e 20 74 | 68 65 20 69 6e 70 75 74 |Return t|he input|
|000005d0| 20 76 61 6c 75 65 2e 20 | 2a 2f 0d 0a 0d 0a 20 20 | value. |*/.... |
|000005e0| 20 20 72 65 74 75 72 6e | 20 69 3b 0d 0a 7d 0d 0a | return| i;..}..|
|000005f0| 0d 0a 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000600| 00 00 01 00 00 00 01 00 | 00 00 00 00 00 00 00 1e |........|........|
|00000610| 54 68 69 73 20 72 65 73 | 6f 75 72 63 65 20 66 6f |This res|ource fo|
|00000620| 72 6b 20 69 6e 74 65 6e | 74 69 6f 6e 61 6c 6c 79 |rk inten|tionally|
|00000630| 20 6c 65 66 74 20 62 6c | 61 6e 6b 20 20 20 00 00 | left bl|ank ..|
|00000640| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000650| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000660| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000670| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000680| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000690| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000700| 00 00 01 00 00 00 01 00 | 00 00 00 00 00 00 00 1e |........|........|
|00000710| 00 00 00 00 00 00 00 00 | 00 1c 00 1e ff ff 00 00 |........|........|
|00000720| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000730| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000740| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000750| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000760| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000770| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+