home *** CD-ROM | disk | FTP | other *** search
/ Sams Teach Yourself C in 21 Days (6th Edition) / STYC216E.ISO / mac / Examples / Day15 / linkdemo.c next >
MacBinary  |  2002-05-12  |  2.0 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, Sun May 12 14:30:06 2002, modified Sun May 12 14:30:06 2002, creator 'LMAN', type ASCII, 1453 bytes "linkdemo.c" , at 0x62d 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 0a 6c 69 6e 6b 64 65 | 6d 6f 2e 63 00 00 00 00 |..linkde|mo.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 ad 00 | 00 01 1e b9 04 65 2e b9 |........|.....e..|
|00000060| 04 65 2e 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |.e......|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 b0 f0 00 00 |........|........|
|00000080| 2f 2a 20 44 65 6d 6f 6e | 73 74 72 61 74 65 73 20 |/* Demon|strates |
|00000090| 74 68 65 20 66 75 6e 64 | 61 6d 65 6e 74 61 6c 73 |the fund|amentals|
|000000a0| 20 6f 66 20 75 73 69 6e | 67 20 2a 2f 0d 0a 2f 2a | of usin|g */../*|
|000000b0| 20 61 20 6c 69 6e 6b 65 | 64 20 6c 69 73 74 2e 20 | a linke|d list. |
|000000c0| 2a 2f 0d 0a 0d 0a 23 69 | 6e 63 6c 75 64 65 20 3c |*/....#i|nclude <|
|000000d0| 73 74 64 6c 69 62 2e 68 | 3e 0d 0a 23 69 6e 63 6c |stdlib.h|>..#incl|
|000000e0| 75 64 65 20 3c 73 74 64 | 69 6f 2e 68 3e 0d 0a 23 |ude <std|io.h>..#|
|000000f0| 69 6e 63 6c 75 64 65 20 | 3c 73 74 72 69 6e 67 2e |include |<string.|
|00000100| 68 3e 0d 0a 0d 0a 2f 2a | 20 54 68 65 20 6c 69 73 |h>..../*| The lis|
|00000110| 74 20 64 61 74 61 20 73 | 74 72 75 63 74 75 72 65 |t data s|tructure|
|00000120| 2e 20 2a 2f 0d 0a 73 74 | 72 75 63 74 20 64 61 74 |. */..st|ruct dat|
|00000130| 61 20 7b 0d 0a 20 20 20 | 20 63 68 61 72 20 6e 61 |a {.. | char na|
|00000140| 6d 65 5b 32 30 5d 3b 0d | 0a 20 20 20 20 73 74 72 |me[20];.|. str|
|00000150| 75 63 74 20 64 61 74 61 | 20 2a 6e 65 78 74 3b 0d |uct data| *next;.|
|00000160| 0a 7d 3b 0d 0a 0d 0a 2f | 2a 20 44 65 66 69 6e 65 |.};..../|* Define|
|00000170| 20 74 79 70 65 64 65 66 | 73 20 66 6f 72 20 74 68 | typedef|s for th|
|00000180| 65 20 73 74 72 75 63 74 | 75 72 65 20 2a 2f 0d 0a |e struct|ure */..|
|00000190| 2f 2a 20 61 6e 64 20 61 | 20 70 6f 69 6e 74 65 72 |/* and a| pointer|
|000001a0| 20 74 6f 20 69 74 2e 20 | 2a 2f 0d 0a 74 79 70 65 | to it. |*/..type|
|000001b0| 64 65 66 20 73 74 72 75 | 63 74 20 64 61 74 61 20 |def stru|ct data |
|000001c0| 50 45 52 53 4f 4e 3b 0d | 0a 74 79 70 65 64 65 66 |PERSON;.|.typedef|
|000001d0| 20 50 45 52 53 4f 4e 20 | 2a 4c 49 4e 4b 3b 0d 0a | PERSON |*LINK;..|
|000001e0| 0d 0a 69 6e 74 20 6d 61 | 69 6e 28 20 76 6f 69 64 |..int ma|in( void|
|000001f0| 20 29 0d 0a 7b 0d 0a 20 | 20 2f 2a 20 48 65 61 64 | )..{.. | /* Head|
|00000200| 2c 20 6e 65 77 2c 20 61 | 6e 64 20 63 75 72 72 65 |, new, a|nd curre|
|00000210| 6e 74 20 65 6c 65 6d 65 | 6e 74 20 70 6f 69 6e 74 |nt eleme|nt point|
|00000220| 65 72 73 2e 20 2a 2f 0d | 0a 20 20 4c 49 4e 4b 20 |ers. */.|. LINK |
|00000230| 68 65 61 64 20 3d 20 4e | 55 4c 4c 3b 0d 0a 20 20 |head = N|ULL;.. |
|00000240| 4c 49 4e 4b 20 6e 65 77 | 20 3d 20 4e 55 4c 4c 3b |LINK new| = NULL;|
|00000250| 0d 0a 20 20 4c 49 4e 4b | 20 63 75 72 72 65 6e 74 |.. LINK| current|
|00000260| 20 3d 20 4e 55 4c 4c 3b | 0d 0a 0d 0a 20 20 2f 2a | = NULL;|.... /*|
|00000270| 20 41 64 64 20 74 68 65 | 20 66 69 72 73 74 20 6c | Add the| first l|
|00000280| 69 73 74 20 65 6c 65 6d | 65 6e 74 2e 20 57 65 20 |ist elem|ent. We |
|00000290| 64 6f 20 6e 6f 74 20 2a | 2f 0d 0a 20 20 2f 2a 20 |do not *|/.. /* |
|000002a0| 61 73 73 75 6d 65 20 74 | 68 65 20 6c 69 73 74 20 |assume t|he list |
|000002b0| 69 73 20 65 6d 70 74 79 | 2c 20 61 6c 74 68 6f 75 |is empty|, althou|
|000002c0| 67 68 20 69 6e 20 2a 2f | 0d 0a 20 20 2f 2a 20 74 |gh in */|.. /* t|
|000002d0| 68 69 73 20 64 65 6d 6f | 20 70 72 6f 67 72 61 6d |his demo| program|
|000002e0| 20 69 74 20 61 6c 77 61 | 79 73 20 77 69 6c 6c 20 | it alwa|ys will |
|000002f0| 62 65 2e 20 2a 2f 0d 0a | 0d 0a 20 20 6e 65 77 20 |be. */..|.. new |
|00000300| 3d 20 28 4c 49 4e 4b 29 | 6d 61 6c 6c 6f 63 28 73 |= (LINK)|malloc(s|
|00000310| 69 7a 65 6f 66 28 50 45 | 52 53 4f 4e 29 29 3b 0d |izeof(PE|RSON));.|
|00000320| 0a 20 20 6e 65 77 2d 3e | 6e 65 78 74 20 3d 20 68 |. new->|next = h|
|00000330| 65 61 64 3b 0d 0a 20 20 | 68 65 61 64 20 3d 20 6e |ead;.. |head = n|
|00000340| 65 77 3b 0d 0a 20 20 73 | 74 72 63 70 79 28 6e 65 |ew;.. s|trcpy(ne|
|00000350| 77 2d 3e 6e 61 6d 65 2c | 20 22 41 62 69 67 61 69 |w->name,| "Abigai|
|00000360| 6c 22 29 3b 0d 0a 0d 0a | 20 20 2f 2a 20 41 64 64 |l");....| /* Add|
|00000370| 20 61 6e 20 65 6c 65 6d | 65 6e 74 20 74 6f 20 74 | an elem|ent to t|
|00000380| 68 65 20 65 6e 64 20 6f | 66 20 74 68 65 20 6c 69 |he end o|f the li|
|00000390| 73 74 2e 20 2a 2f 0d 0a | 20 20 2f 2a 20 57 65 20 |st. */..| /* We |
|000003a0| 61 73 73 75 6d 65 20 74 | 68 65 20 6c 69 73 74 20 |assume t|he list |
|000003b0| 63 6f 6e 74 61 69 6e 73 | 20 61 74 20 6c 65 61 73 |contains| at leas|
|000003c0| 74 20 6f 6e 65 20 65 6c | 65 6d 65 6e 74 2e 20 2a |t one el|ement. *|
|000003d0| 2f 0d 0a 0d 0a 20 20 63 | 75 72 72 65 6e 74 20 3d |/.... c|urrent =|
|000003e0| 20 68 65 61 64 3b 0d 0a | 20 20 77 68 69 6c 65 20 | head;..| while |
|000003f0| 28 63 75 72 72 65 6e 74 | 2d 3e 6e 65 78 74 20 21 |(current|->next !|
|00000400| 3d 20 4e 55 4c 4c 29 0d | 0a 20 20 7b 0d 0a 20 20 |= NULL).|. {.. |
|00000410| 20 20 63 75 72 72 65 6e | 74 20 3d 20 63 75 72 72 | curren|t = curr|
|00000420| 65 6e 74 2d 3e 6e 65 78 | 74 3b 0d 0a 20 20 7d 0d |ent->nex|t;.. }.|
|00000430| 0a 0d 0a 20 20 6e 65 77 | 20 3d 20 28 4c 49 4e 4b |... new| = (LINK|
|00000440| 29 6d 61 6c 6c 6f 63 28 | 73 69 7a 65 6f 66 28 50 |)malloc(|sizeof(P|
|00000450| 45 52 53 4f 4e 29 29 3b | 0d 0a 20 20 63 75 72 72 |ERSON));|.. curr|
|00000460| 65 6e 74 2d 3e 6e 65 78 | 74 20 3d 20 6e 65 77 3b |ent->nex|t = new;|
|00000470| 0d 0a 20 20 6e 65 77 2d | 3e 6e 65 78 74 20 3d 20 |.. new-|>next = |
|00000480| 4e 55 4c 4c 3b 0d 0a 20 | 20 73 74 72 63 70 79 28 |NULL;.. | strcpy(|
|00000490| 6e 65 77 2d 3e 6e 61 6d | 65 2c 20 22 43 61 72 6f |new->nam|e, "Caro|
|000004a0| 6c 79 6e 22 29 3b 0d 0a | 0d 0a 20 20 2f 2a 20 41 |lyn");..|.. /* A|
|000004b0| 64 64 20 61 20 6e 65 77 | 20 65 6c 65 6d 65 6e 74 |dd a new| element|
|000004c0| 20 61 74 20 74 68 65 20 | 73 65 63 6f 6e 64 20 70 | at the |second p|
|000004d0| 6f 73 69 74 69 6f 6e 20 | 69 6e 20 74 68 65 20 6c |osition |in the l|
|000004e0| 69 73 74 2e 20 2a 2f 0d | 0a 20 20 6e 65 77 20 3d |ist. */.|. new =|
|000004f0| 20 28 4c 49 4e 4b 29 6d | 61 6c 6c 6f 63 28 73 69 | (LINK)m|alloc(si|
|00000500| 7a 65 6f 66 28 50 45 52 | 53 4f 4e 29 29 3b 0d 0a |zeof(PER|SON));..|
|00000510| 20 20 6e 65 77 2d 3e 6e | 65 78 74 20 3d 20 68 65 | new->n|ext = he|
|00000520| 61 64 2d 3e 6e 65 78 74 | 3b 0d 0a 20 20 68 65 61 |ad->next|;.. hea|
|00000530| 64 2d 3e 6e 65 78 74 20 | 3d 20 6e 65 77 3b 0d 0a |d->next |= new;..|
|00000540| 20 20 73 74 72 63 70 79 | 28 6e 65 77 2d 3e 6e 61 | strcpy|(new->na|
|00000550| 6d 65 2c 20 22 42 65 61 | 74 72 69 63 65 22 29 3b |me, "Bea|trice");|
|00000560| 0d 0a 0d 0a 20 20 2f 2a | 20 50 72 69 6e 74 20 61 |.... /*| Print a|
|00000570| 6c 6c 20 64 61 74 61 20 | 69 74 65 6d 73 20 69 6e |ll data |items in|
|00000580| 20 6f 72 64 65 72 2e 20 | 2a 2f 0d 0a 20 20 63 75 | order. |*/.. cu|
|00000590| 72 72 65 6e 74 20 3d 20 | 68 65 61 64 3b 0d 0a 20 |rrent = |head;.. |
|000005a0| 20 77 68 69 6c 65 20 28 | 63 75 72 72 65 6e 74 20 | while (|current |
|000005b0| 21 3d 20 4e 55 4c 4c 29 | 0d 0a 20 20 7b 0d 0a 20 |!= NULL)|.. {.. |
|000005c0| 20 20 20 70 72 69 6e 74 | 66 28 22 5c 6e 25 73 22 | print|f("\n%s"|
|000005d0| 2c 20 63 75 72 72 65 6e | 74 2d 3e 6e 61 6d 65 29 |, curren|t->name)|
|000005e0| 3b 0d 0a 20 20 20 20 63 | 75 72 72 65 6e 74 20 3d |;.. c|urrent =|
|000005f0| 20 63 75 72 72 65 6e 74 | 2d 3e 6e 65 78 74 3b 0d | current|->next;.|
|00000600| 0a 20 20 7d 0d 0a 0d 0a | 20 20 70 72 69 6e 74 66 |. }....| printf|
|00000610| 28 22 5c 6e 22 29 3b 0d | 0a 0d 0a 20 20 72 65 74 |("\n");.|... ret|
|00000620| 75 72 6e 20 30 3b 0d 0a | 7d 0d 0a 0d 0a 00 00 00 |urn 0;..|}.......|
|00000630| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|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 01 00 00 00 01 00 | 00 00 00 00 00 00 00 1e |........|........|
|00000690| 54 68 69 73 20 72 65 73 | 6f 75 72 63 65 20 66 6f |This res|ource fo|
|000006a0| 72 6b 20 69 6e 74 65 6e | 74 69 6f 6e 61 6c 6c 79 |rk inten|tionally|
|000006b0| 20 6c 65 66 74 20 62 6c | 61 6e 6b 20 20 20 00 00 | left bl|ank ..|
|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 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000710| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 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 |........|........|
|00000780| 00 00 01 00 00 00 01 00 | 00 00 00 00 00 00 00 1e |........|........|
|00000790| 00 00 00 00 00 00 00 00 | 00 1c 00 1e ff ff 00 00 |........|........|
|000007a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000007b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000007c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000007d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000007e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000007f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+