home *** CD-ROM | disk | FTP | other *** search
/ Sams Teach Yourself C in 21 Days (6th Edition) / STYC216E.ISO / mac / Examples / Day16 / fprintf.c < prev    next >
MacBinary  |  2002-08-11  |  1.6 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 Aug 11 11:03:30 2002, modified Sun Aug 11 11:03:30 2002, creator 'LMAN', type ASCII, 1089 bytes "fprintf.c" , at 0x4c1 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 09 66 70 72 69 6e 74 | 66 2e 63 00 00 00 00 00 |..fprint|f.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 04 41 00 | 00 01 1e b9 7c 2d 42 b9 |......A.|....|-B.|
|00000060| 7c 2d 42 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ||-B.....|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 12 07 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 70 72 69 | 6e 74 66 28 29 20 66 75 |the fpri|ntf() fu|
|000000a0| 6e 63 74 69 6f 6e 2e 20 | 2a 2f 0d 0a 23 69 6e 63 |nction. |*/..#inc|
|000000b0| 6c 75 64 65 20 3c 73 74 | 64 6c 69 62 2e 68 3e 0d |lude <st|dlib.h>.|
|000000c0| 0a 23 69 6e 63 6c 75 64 | 65 20 3c 73 74 64 69 6f |.#includ|e <stdio|
|000000d0| 2e 68 3e 0d 0a 0d 0a 76 | 6f 69 64 20 63 6c 65 61 |.h>....v|oid clea|
|000000e0| 72 5f 6b 62 28 76 6f 69 | 64 29 3b 0d 0a 0d 0a 69 |r_kb(voi|d);....i|
|000000f0| 6e 74 20 6d 61 69 6e 28 | 20 76 6f 69 64 20 29 0d |nt main(| void ).|
|00000100| 0a 7b 0d 0a 20 20 20 20 | 46 49 4c 45 20 2a 66 70 |.{.. |FILE *fp|
|00000110| 3b 0d 0a 20 20 20 20 66 | 6c 6f 61 74 20 64 61 74 |;.. f|loat dat|
|00000120| 61 5b 35 5d 3b 0d 0a 20 | 20 20 20 69 6e 74 20 63 |a[5];.. | int c|
|00000130| 6f 75 6e 74 3b 0d 0a 20 | 20 20 20 63 68 61 72 20 |ount;.. | char |
|00000140| 66 69 6c 65 6e 61 6d 65 | 5b 32 30 5d 3b 0d 0a 0d |filename|[20];...|
|00000150| 0a 20 20 20 20 70 75 74 | 73 28 22 45 6e 74 65 72 |. put|s("Enter|
|00000160| 20 35 20 66 6c 6f 61 74 | 69 6e 67 2d 70 6f 69 6e | 5 float|ing-poin|
|00000170| 74 20 6e 75 6d 65 72 69 | 63 61 6c 20 76 61 6c 75 |t numeri|cal valu|
|00000180| 65 73 2e 22 29 3b 0d 0a | 0d 0a 20 20 20 20 66 6f |es.");..|.. fo|
|00000190| 72 20 28 63 6f 75 6e 74 | 20 3d 20 30 3b 20 63 6f |r (count| = 0; co|
|000001a0| 75 6e 74 20 3c 20 35 3b | 20 63 6f 75 6e 74 2b 2b |unt < 5;| count++|
|000001b0| 29 0d 0a 20 20 20 20 20 | 20 20 20 73 63 61 6e 66 |).. | scanf|
|000001c0| 28 22 25 66 22 2c 20 26 | 64 61 74 61 5b 63 6f 75 |("%f", &|data[cou|
|000001d0| 6e 74 5d 29 3b 0d 0a 0d | 0a 20 20 20 20 2f 2a 20 |nt]);...|. /* |
|000001e0| 47 65 74 20 74 68 65 20 | 66 69 6c 65 6e 61 6d 65 |Get the |filename|
|000001f0| 20 61 6e 64 20 6f 70 65 | 6e 20 74 68 65 20 66 69 | and ope|n the fi|
|00000200| 6c 65 2e 20 46 69 72 73 | 74 20 63 6c 65 61 72 20 |le. Firs|t clear |
|00000210| 73 74 64 69 6e 20 2a 2f | 0d 0a 20 20 20 20 2f 2a |stdin */|.. /*|
|00000220| 20 6f 66 20 61 6e 79 20 | 65 78 74 72 61 20 63 68 | of any |extra ch|
|00000230| 61 72 61 63 74 65 72 73 | 2e 20 2a 2f 0d 0a 0d 0a |aracters|. */....|
|00000240| 20 20 20 20 63 6c 65 61 | 72 5f 6b 62 28 29 3b 0d | clea|r_kb();.|
|00000250| 0a 0d 0a 20 20 20 20 70 | 75 74 73 28 22 45 6e 74 |... p|uts("Ent|
|00000260| 65 72 20 61 20 6e 61 6d | 65 20 66 6f 72 20 74 68 |er a nam|e for th|
|00000270| 65 20 66 69 6c 65 2e 22 | 29 3b 0d 0a 20 20 20 20 |e file."|);.. |
|00000280| 67 65 74 73 28 66 69 6c | 65 6e 61 6d 65 29 3b 0d |gets(fil|ename);.|
|00000290| 0a 0d 0a 20 20 20 20 69 | 66 20 28 20 28 66 70 20 |... i|f ( (fp |
|000002a0| 3d 20 66 6f 70 65 6e 28 | 66 69 6c 65 6e 61 6d 65 |= fopen(|filename|
|000002b0| 2c 20 22 77 22 29 29 20 | 3d 3d 20 4e 55 4c 4c 29 |, "w")) |== NULL)|
|000002c0| 0d 0a 20 20 20 20 7b 0d | 0a 20 20 20 20 20 20 20 |.. {.|. |
|000002d0| 20 66 70 72 69 6e 74 66 | 28 73 74 64 65 72 72 2c | fprintf|(stderr,|
|000002e0| 20 22 45 72 72 6f 72 20 | 6f 70 65 6e 69 6e 67 20 | "Error |opening |
|000002f0| 66 69 6c 65 20 25 73 2e | 22 2c 20 66 69 6c 65 6e |file %s.|", filen|
|00000300| 61 6d 65 29 3b 0d 0a 20 | 20 20 20 20 20 20 20 65 |ame);.. | e|
|00000310| 78 69 74 28 31 29 3b 0d | 0a 20 20 20 20 7d 0d 0a |xit(1);.|. }..|
|00000320| 0d 0a 20 20 20 20 2f 2a | 20 57 72 69 74 65 20 74 |.. /*| Write t|
|00000330| 68 65 20 6e 75 6d 65 72 | 69 63 61 6c 20 64 61 74 |he numer|ical dat|
|00000340| 61 20 74 6f 20 74 68 65 | 20 66 69 6c 65 20 61 6e |a to the| file an|
|00000350| 64 20 74 6f 20 73 74 64 | 6f 75 74 2e 20 2a 2f 0d |d to std|out. */.|
|00000360| 0a 0d 0a 20 20 20 20 66 | 6f 72 20 28 63 6f 75 6e |... f|or (coun|
|00000370| 74 20 3d 20 30 3b 20 63 | 6f 75 6e 74 20 3c 20 35 |t = 0; c|ount < 5|
|00000380| 3b 20 63 6f 75 6e 74 2b | 2b 29 0d 0a 20 20 20 20 |; count+|+).. |
|00000390| 7b 0d 0a 20 20 20 20 20 | 20 20 20 66 70 72 69 6e |{.. | fprin|
|000003a0| 74 66 28 66 70 2c 20 22 | 5c 6e 64 61 74 61 5b 25 |tf(fp, "|\ndata[%|
|000003b0| 64 5d 20 3d 20 25 66 22 | 2c 20 63 6f 75 6e 74 2c |d] = %f"|, count,|
|000003c0| 20 64 61 74 61 5b 63 6f | 75 6e 74 5d 29 3b 0d 0a | data[co|unt]);..|
|000003d0| 20 20 20 20 20 20 20 20 | 66 70 72 69 6e 74 66 28 | |fprintf(|
|000003e0| 73 74 64 6f 75 74 2c 20 | 22 5c 6e 64 61 74 61 5b |stdout, |"\ndata[|
|000003f0| 25 64 5d 20 3d 20 25 66 | 22 2c 20 63 6f 75 6e 74 |%d] = %f|", count|
|00000400| 2c 20 64 61 74 61 5b 63 | 6f 75 6e 74 5d 29 3b 0d |, data[c|ount]);.|
|00000410| 0a 20 20 20 20 7d 0d 0a | 20 20 20 20 66 63 6c 6f |. }..| fclo|
|00000420| 73 65 28 66 70 29 3b 0d | 0a 20 20 20 20 70 72 69 |se(fp);.|. pri|
|00000430| 6e 74 66 28 22 5c 6e 22 | 29 3b 0d 0a 20 20 20 20 |ntf("\n"|);.. |
|00000440| 72 65 74 75 72 6e 20 30 | 3b 0d 0a 7d 0d 0a 0d 0a |return 0|;..}....|
|00000450| 76 6f 69 64 20 63 6c 65 | 61 72 5f 6b 62 28 76 6f |void cle|ar_kb(vo|
|00000460| 69 64 29 0d 0a 2f 2a 20 | 43 6c 65 61 72 73 20 73 |id)../* |Clears s|
|00000470| 74 64 69 6e 20 6f 66 20 | 61 6e 79 20 77 61 69 74 |tdin of |any wait|
|00000480| 69 6e 67 20 63 68 61 72 | 61 63 74 65 72 73 2e 20 |ing char|acters. |
|00000490| 2a 2f 0d 0a 7b 0d 0a 20 | 20 20 20 63 68 61 72 20 |*/..{.. | char |
|000004a0| 6a 75 6e 6b 5b 38 30 5d | 3b 0d 0a 20 20 20 20 67 |junk[80]|;.. g|
|000004b0| 65 74 73 28 6a 75 6e 6b | 29 3b 0d 0a 7d 0d 0a 0d |ets(junk|);..}...|
|000004c0| 0a 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000004d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000004e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000004f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000500| 00 00 01 00 00 00 01 00 | 00 00 00 00 00 00 00 1e |........|........|
|00000510| 54 68 69 73 20 72 65 73 | 6f 75 72 63 65 20 66 6f |This res|ource fo|
|00000520| 72 6b 20 69 6e 74 65 6e | 74 69 6f 6e 61 6c 6c 79 |rk inten|tionally|
|00000530| 20 6c 65 66 74 20 62 6c | 61 6e 6b 20 20 20 00 00 | left bl|ank ..|
|00000540| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000550| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000560| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000570| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000580| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000590| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005f0| 00 00 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| 00 00 00 00 00 00 00 00 | 00 1c 00 1e ff ff 00 00 |........|........|
|00000620| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|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 |........|........|
+--------+-------------------------+-------------------------+--------+--------+