Home » Archimedes archive » Acorn User » AU 1994-02.adf » !C_Interp_C_Interp » Examples/stdio
Examples/stdio
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-02.adf » !C_Interp_C_Interp |
Filename: | Examples/stdio |
Read OK: | ✔ |
File size: | 0241 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
@* An example of some stdio library routines *@ main() { char text[40]; int fileptr, i; bbc_mode(12); sprintf(text,">>TEXT<<"); printf("This is a simple stdio test program: %s\n",text); fileptr = fopen("testfile","w"); if(!fileptr) puts("Can't open output file!"); else { for(i=0; i<20; i++) { fprintf(fileptr,"\nThis is some text in a file (line %d).",i+1); } fclose(fileptr); } for(fileptr=fopen("testfile","r"); !feof(fileptr);) { fgets(text,39,fileptr); if(!feof(fileptr)) printf("%s",text); } fclose(fileptr); remove("testfile"); }
00000000 40 2a 20 41 6e 20 65 78 61 6d 70 6c 65 20 6f 66 |@* An example of| 00000010 20 73 6f 6d 65 20 73 74 64 69 6f 20 6c 69 62 72 | some stdio libr| 00000020 61 72 79 20 72 6f 75 74 69 6e 65 73 20 2a 40 0a |ary routines *@.| 00000030 0a 6d 61 69 6e 28 29 0a 7b 0a 63 68 61 72 20 74 |.main().{.char t| 00000040 65 78 74 5b 34 30 5d 3b 0a 69 6e 74 20 66 69 6c |ext[40];.int fil| 00000050 65 70 74 72 2c 20 69 3b 0a 0a 62 62 63 5f 6d 6f |eptr, i;..bbc_mo| 00000060 64 65 28 31 32 29 3b 0a 0a 73 70 72 69 6e 74 66 |de(12);..sprintf| 00000070 28 74 65 78 74 2c 22 3e 3e 54 45 58 54 3c 3c 22 |(text,">>TEXT<<"| 00000080 29 3b 0a 70 72 69 6e 74 66 28 22 54 68 69 73 20 |);.printf("This | 00000090 69 73 20 61 20 73 69 6d 70 6c 65 20 73 74 64 69 |is a simple stdi| 000000a0 6f 20 74 65 73 74 20 70 72 6f 67 72 61 6d 3a 20 |o test program: | 000000b0 25 73 5c 6e 22 2c 74 65 78 74 29 3b 0a 0a 66 69 |%s\n",text);..fi| 000000c0 6c 65 70 74 72 20 3d 20 66 6f 70 65 6e 28 22 74 |leptr = fopen("t| 000000d0 65 73 74 66 69 6c 65 22 2c 22 77 22 29 3b 0a 69 |estfile","w");.i| 000000e0 66 28 21 66 69 6c 65 70 74 72 29 0a 20 20 70 75 |f(!fileptr). pu| 000000f0 74 73 28 22 43 61 6e 27 74 20 6f 70 65 6e 20 6f |ts("Can't open o| 00000100 75 74 70 75 74 20 66 69 6c 65 21 22 29 3b 0a 65 |utput file!");.e| 00000110 6c 73 65 0a 20 20 7b 0a 20 20 66 6f 72 28 69 3d |lse. {. for(i=| 00000120 30 3b 20 69 3c 32 30 3b 20 69 2b 2b 29 0a 20 20 |0; i<20; i++). | 00000130 20 20 7b 0a 20 20 20 20 66 70 72 69 6e 74 66 28 | {. fprintf(| 00000140 66 69 6c 65 70 74 72 2c 22 5c 6e 54 68 69 73 20 |fileptr,"\nThis | 00000150 69 73 20 73 6f 6d 65 20 74 65 78 74 20 69 6e 20 |is some text in | 00000160 61 20 66 69 6c 65 20 28 6c 69 6e 65 20 25 64 29 |a file (line %d)| 00000170 2e 22 2c 69 2b 31 29 3b 0a 20 20 20 20 7d 0a 20 |.",i+1);. }. | 00000180 20 66 63 6c 6f 73 65 28 66 69 6c 65 70 74 72 29 | fclose(fileptr)| 00000190 3b 0a 20 20 7d 0a 0a 66 6f 72 28 66 69 6c 65 70 |;. }..for(filep| 000001a0 74 72 3d 66 6f 70 65 6e 28 22 74 65 73 74 66 69 |tr=fopen("testfi| 000001b0 6c 65 22 2c 22 72 22 29 3b 20 21 66 65 6f 66 28 |le","r"); !feof(| 000001c0 66 69 6c 65 70 74 72 29 3b 29 0a 20 20 7b 0a 20 |fileptr);). {. | 000001d0 20 66 67 65 74 73 28 74 65 78 74 2c 33 39 2c 66 | fgets(text,39,f| 000001e0 69 6c 65 70 74 72 29 3b 0a 20 20 69 66 28 21 66 |ileptr);. if(!f| 000001f0 65 6f 66 28 66 69 6c 65 70 74 72 29 29 0a 20 20 |eof(fileptr)). | 00000200 20 20 70 72 69 6e 74 66 28 22 25 73 22 2c 74 65 | printf("%s",te| 00000210 78 74 29 3b 0a 20 20 7d 0a 66 63 6c 6f 73 65 28 |xt);. }.fclose(| 00000220 66 69 6c 65 70 74 72 29 3b 0a 0a 72 65 6d 6f 76 |fileptr);..remov| 00000230 65 28 22 74 65 73 74 66 69 6c 65 22 29 3b 0a 7d |e("testfile");.}| 00000240 0a |.| 00000241