Home » Archimedes archive » Acorn User » AU 1994-Xmas.adf » Programs » C/c/Kate2
C/c/Kate2
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-Xmas.adf » Programs |
Filename: | C/c/Kate2 |
Read OK: | ✔ |
File size: | 127E bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* Kate 2: the second fragment of the grand photo-cataloguing program. */ /* Include header files to define functions for I/O and string handling. */ #include <stdio.h> #include <string.h> #include <stdlib.h> /* Main program. */ main() { int exposure[40]; int aperture[40][2]; char *place[40]; /* This time, initialise place as an array of */ /* pointers. */ int i,max_frames,len; float datum; char buffer[256]; /* Buffer is where the text for the location of */ /* each photograph is placed, while the length of */ /* the text is assessed. */ printf("Please enter the number of frames on the film.\n"); printf("(Up to forty.)\n"); /* The scanf() function reads values in from the keyboard. The first */ /* function argument is a formatting string; the second */ /* argument gives the _address_ of the datum to be read in (hence */ /* it is prefixed by an ampersand). The maximum number of frames is */ /* checked to make sure that it is a sensible number. */ scanf("%d",&max_frames); if (max_frames > 40) max_frames = 40; if (max_frames < 1) max_frames = 1; printf("You will now be asked to enter exposure, aperture and\n"); printf("location data for each frame on the film.\n"); printf("If the exposure is less than one second, it should be\n"); printf("entered as minus the reciprocal of the exposure. For\n"); printf("instance, an exposure of a thirtieth of a second should\n"); printf("be entered as \"-30\".\n"); printf("All locations should be shorter than 255 characters long.\n"); /* The program now goes through a loop. The loop starts from zero. This */ /* is deliberate, and is because most films actually start from frame */ /* zero, unless you get over-enthusiastic while loading the film. */ /* Each array has 40 elements, so the highest index for any of the */ /* arrays should be 39. */ for (i=0; i<max_frames; i++) { printf("Please enter the exposure of frame %d.\n",i); scanf("%d",&exposure[i]); printf("Please enter the aperture setting for frame %d.\n",i); /* The aperture is read as a floating point number, and the integer and */ /* the first decimal place parts of the number are held in elements zero */ /* and one of the array. */ scanf("%f",&datum); aperture[i][0] = (int)datum; aperture[i][1] = (datum - aperture[i][0]) * 10; printf("Please enter the loction for frame %d.\n",i); getchar(); /* The gets() function reads a line of text from the keyboard into a */ /* string. It takes as an argument a pointer to the string. This could */ /* be written '&buffer[0]', since that is where we want the string to */ /* go, but this is just a pointer to element zero of the array and so */ /* so can also be written 'buffer'. */ gets(buffer); /* strlen() returns the length of a string. It does _not_ include the */ /* terminating zero byte. */ len = strlen(buffer); /* Set up the pointer in place[i] to point to an area big enough to hold */ /* the string just input. Note: 1) sizeof(char) is assumed to be one, so */ /* not needed in the malloc() statement and 2) the block must be one */ /* byte longer than the number of characters in the string to allow for */ /* the terminating zero. */ place[i] = malloc(len+1); /* strcpy() copies one string to another string - which cannot be done */ /* in C by a simple string1=string2 command. In this case, the string */ /* pointed to by the pointer 'buffer' is copied to the memory block */ /* pointed to by the pointer 'place[i]'. The copying stops when a */ /* terminating zero is enountered in the string pointed to by buffer. */ strcpy(place[i],buffer); } /* The next loop prints out all the values that we have just input. */ for (i=0; i<max_frames; i++) { printf("Exposure %d was taken at %s\n",i,place[i]); if (exposure[i] > 0) { printf("with an exposure of %d ",exposure[i]); } else { printf("with an exposure of 1/%d ",-exposure[i]); } printf("and an aperture of %d.%d.\n\n",aperture[i][0],aperture[i][1]); } /* Since main() is technically a function, we should return zero from */ /* it to reassure the machine that everything has gone well. Don't */ /* worry about this for the moment. */ return 0; }
00000000 2f 2a 20 4b 61 74 65 20 32 3a 20 74 68 65 20 73 |/* Kate 2: the s| 00000010 65 63 6f 6e 64 20 66 72 61 67 6d 65 6e 74 20 6f |econd fragment o| 00000020 66 20 74 68 65 20 67 72 61 6e 64 20 70 68 6f 74 |f the grand phot| 00000030 6f 2d 63 61 74 61 6c 6f 67 75 69 6e 67 20 70 72 |o-cataloguing pr| 00000040 6f 67 72 61 6d 2e 20 20 20 2a 2f 0a 0a 2f 2a 20 |ogram. */../* | 00000050 49 6e 63 6c 75 64 65 20 68 65 61 64 65 72 20 66 |Include header f| 00000060 69 6c 65 73 20 74 6f 20 64 65 66 69 6e 65 20 66 |iles to define f| 00000070 75 6e 63 74 69 6f 6e 73 20 66 6f 72 20 49 2f 4f |unctions for I/O| 00000080 20 61 6e 64 20 73 74 72 69 6e 67 20 68 61 6e 64 | and string hand| 00000090 6c 69 6e 67 2e 20 2a 2f 0a 23 69 6e 63 6c 75 64 |ling. */.#includ| 000000a0 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 |e <stdio.h>.#inc| 000000b0 6c 75 64 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a |lude <string.h>.| 000000c0 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 6c 69 62 |#include <stdlib| 000000d0 2e 68 3e 0a 0a 2f 2a 20 4d 61 69 6e 20 70 72 6f |.h>../* Main pro| 000000e0 67 72 61 6d 2e 20 2a 2f 0a 6d 61 69 6e 28 29 0a |gram. */.main().| 000000f0 7b 20 69 6e 74 20 65 78 70 6f 73 75 72 65 5b 34 |{ int exposure[4| 00000100 30 5d 3b 0a 20 20 69 6e 74 20 61 70 65 72 74 75 |0];. int apertu| 00000110 72 65 5b 34 30 5d 5b 32 5d 3b 0a 20 20 63 68 61 |re[40][2];. cha| 00000120 72 20 2a 70 6c 61 63 65 5b 34 30 5d 3b 20 20 20 |r *place[40]; | 00000130 20 20 2f 2a 20 54 68 69 73 20 74 69 6d 65 2c 20 | /* This time, | 00000140 69 6e 69 74 69 61 6c 69 73 65 20 70 6c 61 63 65 |initialise place| 00000150 20 61 73 20 61 6e 20 61 72 72 61 79 20 6f 66 20 | as an array of | 00000160 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 | */. | 00000170 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a | /*| 00000180 20 70 6f 69 6e 74 65 72 73 2e 20 20 20 20 20 20 | pointers. | 00000190 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 000001b0 2a 2f 0a 20 20 69 6e 74 20 69 2c 6d 61 78 5f 66 |*/. int i,max_f| 000001c0 72 61 6d 65 73 2c 6c 65 6e 3b 0a 20 20 66 6c 6f |rames,len;. flo| 000001d0 61 74 20 64 61 74 75 6d 3b 0a 20 20 63 68 61 72 |at datum;. char| 000001e0 20 62 75 66 66 65 72 5b 32 35 36 5d 3b 20 20 20 | buffer[256]; | 000001f0 20 2f 2a 20 42 75 66 66 65 72 20 69 73 20 77 68 | /* Buffer is wh| 00000200 65 72 65 20 74 68 65 20 74 65 78 74 20 66 6f 72 |ere the text for| 00000210 20 74 68 65 20 6c 6f 63 61 74 69 6f 6e 20 6f 66 | the location of| 00000220 20 20 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 | */. | 00000230 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 | /* | 00000240 65 61 63 68 20 70 68 6f 74 6f 67 72 61 70 68 20 |each photograph | 00000250 69 73 20 70 6c 61 63 65 64 2c 20 77 68 69 6c 65 |is placed, while| 00000260 20 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 2a | the length of *| 00000270 2f 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |/. | 00000280 20 20 20 20 20 20 20 20 20 2f 2a 20 74 68 65 20 | /* the | 00000290 74 65 78 74 20 69 73 20 61 73 73 65 73 73 65 64 |text is assessed| 000002a0 2e 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |. | 000002b0 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 0a 20 | */.. | 000002c0 20 70 72 69 6e 74 66 28 22 50 6c 65 61 73 65 20 | printf("Please | 000002d0 65 6e 74 65 72 20 74 68 65 20 6e 75 6d 62 65 72 |enter the number| 000002e0 20 6f 66 20 66 72 61 6d 65 73 20 6f 6e 20 74 68 | of frames on th| 000002f0 65 20 66 69 6c 6d 2e 5c 6e 22 29 3b 0a 20 20 70 |e film.\n");. p| 00000300 72 69 6e 74 66 28 22 28 55 70 20 74 6f 20 66 6f |rintf("(Up to fo| 00000310 72 74 79 2e 29 5c 6e 22 29 3b 0a 0a 2f 2a 20 54 |rty.)\n");../* T| 00000320 68 65 20 73 63 61 6e 66 28 29 20 66 75 6e 63 74 |he scanf() funct| 00000330 69 6f 6e 20 72 65 61 64 73 20 76 61 6c 75 65 73 |ion reads values| 00000340 20 69 6e 20 66 72 6f 6d 20 74 68 65 20 6b 65 79 | in from the key| 00000350 62 6f 61 72 64 2e 20 54 68 65 20 66 69 72 73 74 |board. The first| 00000360 20 20 20 20 20 2a 2f 0a 2f 2a 20 66 75 6e 63 74 | */./* funct| 00000370 69 6f 6e 20 61 72 67 75 6d 65 6e 74 20 69 73 20 |ion argument is | 00000380 61 20 66 6f 72 6d 61 74 74 69 6e 67 20 73 74 72 |a formatting str| 00000390 69 6e 67 3b 20 74 68 65 20 73 65 63 6f 6e 64 20 |ing; the second | 000003a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000003b0 20 2a 2f 0a 2f 2a 20 61 72 67 75 6d 65 6e 74 20 | */./* argument | 000003c0 67 69 76 65 73 20 74 68 65 20 5f 61 64 64 72 65 |gives the _addre| 000003d0 73 73 5f 20 6f 66 20 74 68 65 20 64 61 74 75 6d |ss_ of the datum| 000003e0 20 74 6f 20 62 65 20 72 65 61 64 20 69 6e 20 28 | to be read in (| 000003f0 68 65 6e 63 65 20 20 20 20 20 20 20 20 2a 2f 0a |hence */.| 00000400 2f 2a 20 69 74 20 69 73 20 70 72 65 66 69 78 65 |/* it is prefixe| 00000410 64 20 62 79 20 61 6e 20 61 6d 70 65 72 73 61 6e |d by an ampersan| 00000420 64 29 2e 20 54 68 65 20 6d 61 78 69 6d 75 6d 20 |d). The maximum | 00000430 6e 75 6d 62 65 72 20 6f 66 20 66 72 61 6d 65 73 |number of frames| 00000440 20 69 73 20 20 20 20 20 20 2a 2f 0a 2f 2a 20 63 | is */./* c| 00000450 68 65 63 6b 65 64 20 74 6f 20 6d 61 6b 65 20 73 |hecked to make s| 00000460 75 72 65 20 74 68 61 74 20 69 74 20 69 73 20 61 |ure that it is a| 00000470 20 73 65 6e 73 69 62 6c 65 20 6e 75 6d 62 65 72 | sensible number| 00000480 2e 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |. | 00000490 20 20 20 20 20 2a 2f 0a 0a 20 20 73 63 61 6e 66 | */.. scanf| 000004a0 28 22 25 64 22 2c 26 6d 61 78 5f 66 72 61 6d 65 |("%d",&max_frame| 000004b0 73 29 3b 0a 20 20 69 66 20 28 6d 61 78 5f 66 72 |s);. if (max_fr| 000004c0 61 6d 65 73 20 3e 20 34 30 29 20 6d 61 78 5f 66 |ames > 40) max_f| 000004d0 72 61 6d 65 73 20 3d 20 34 30 3b 0a 20 20 69 66 |rames = 40;. if| 000004e0 20 28 6d 61 78 5f 66 72 61 6d 65 73 20 3c 20 20 | (max_frames < | 000004f0 31 29 20 6d 61 78 5f 66 72 61 6d 65 73 20 3d 20 |1) max_frames = | 00000500 31 3b 0a 0a 20 20 70 72 69 6e 74 66 28 22 59 6f |1;.. printf("Yo| 00000510 75 20 77 69 6c 6c 20 6e 6f 77 20 62 65 20 61 73 |u will now be as| 00000520 6b 65 64 20 74 6f 20 65 6e 74 65 72 20 65 78 70 |ked to enter exp| 00000530 6f 73 75 72 65 2c 20 61 70 65 72 74 75 72 65 20 |osure, aperture | 00000540 61 6e 64 5c 6e 22 29 3b 0a 20 20 70 72 69 6e 74 |and\n");. print| 00000550 66 28 22 6c 6f 63 61 74 69 6f 6e 20 64 61 74 61 |f("location data| 00000560 20 66 6f 72 20 65 61 63 68 20 66 72 61 6d 65 20 | for each frame | 00000570 6f 6e 20 74 68 65 20 66 69 6c 6d 2e 5c 6e 22 29 |on the film.\n")| 00000580 3b 0a 20 20 70 72 69 6e 74 66 28 22 49 66 20 74 |;. printf("If t| 00000590 68 65 20 65 78 70 6f 73 75 72 65 20 69 73 20 6c |he exposure is l| 000005a0 65 73 73 20 74 68 61 6e 20 6f 6e 65 20 73 65 63 |ess than one sec| 000005b0 6f 6e 64 2c 20 69 74 20 73 68 6f 75 6c 64 20 62 |ond, it should b| 000005c0 65 5c 6e 22 29 3b 0a 20 20 70 72 69 6e 74 66 28 |e\n");. printf(| 000005d0 22 65 6e 74 65 72 65 64 20 61 73 20 6d 69 6e 75 |"entered as minu| 000005e0 73 20 74 68 65 20 72 65 63 69 70 72 6f 63 61 6c |s the reciprocal| 000005f0 20 6f 66 20 74 68 65 20 65 78 70 6f 73 75 72 65 | of the exposure| 00000600 2e 20 46 6f 72 5c 6e 22 29 3b 0a 20 20 70 72 69 |. For\n");. pri| 00000610 6e 74 66 28 22 69 6e 73 74 61 6e 63 65 2c 20 61 |ntf("instance, a| 00000620 6e 20 65 78 70 6f 73 75 72 65 20 6f 66 20 61 20 |n exposure of a | 00000630 74 68 69 72 74 69 65 74 68 20 6f 66 20 61 20 73 |thirtieth of a s| 00000640 65 63 6f 6e 64 20 73 68 6f 75 6c 64 5c 6e 22 29 |econd should\n")| 00000650 3b 0a 20 20 70 72 69 6e 74 66 28 22 62 65 20 65 |;. printf("be e| 00000660 6e 74 65 72 65 64 20 61 73 20 5c 22 2d 33 30 5c |ntered as \"-30\| 00000670 22 2e 5c 6e 22 29 3b 0a 20 20 70 72 69 6e 74 66 |".\n");. printf| 00000680 28 22 41 6c 6c 20 6c 6f 63 61 74 69 6f 6e 73 20 |("All locations | 00000690 73 68 6f 75 6c 64 20 62 65 20 73 68 6f 72 74 65 |should be shorte| 000006a0 72 20 74 68 61 6e 20 32 35 35 20 63 68 61 72 61 |r than 255 chara| 000006b0 63 74 65 72 73 20 6c 6f 6e 67 2e 5c 6e 22 29 3b |cters long.\n");| 000006c0 0a 0a 2f 2a 20 54 68 65 20 70 72 6f 67 72 61 6d |../* The program| 000006d0 20 6e 6f 77 20 67 6f 65 73 20 74 68 72 6f 75 67 | now goes throug| 000006e0 68 20 61 20 6c 6f 6f 70 2e 20 54 68 65 20 6c 6f |h a loop. The lo| 000006f0 6f 70 20 73 74 61 72 74 73 20 66 72 6f 6d 20 7a |op starts from z| 00000700 65 72 6f 2e 20 54 68 69 73 20 20 2a 2f 0a 2f 2a |ero. This */./*| 00000710 20 69 73 20 64 65 6c 69 62 65 72 61 74 65 2c 20 | is deliberate, | 00000720 61 6e 64 20 69 73 20 62 65 63 61 75 73 65 20 6d |and is because m| 00000730 6f 73 74 20 66 69 6c 6d 73 20 61 63 74 75 61 6c |ost films actual| 00000740 6c 79 20 73 74 61 72 74 20 66 72 6f 6d 20 66 72 |ly start from fr| 00000750 61 6d 65 20 20 20 20 2a 2f 0a 2f 2a 20 7a 65 72 |ame */./* zer| 00000760 6f 2c 20 75 6e 6c 65 73 73 20 79 6f 75 20 67 65 |o, unless you ge| 00000770 74 20 6f 76 65 72 2d 65 6e 74 68 75 73 69 61 73 |t over-enthusias| 00000780 74 69 63 20 77 68 69 6c 65 20 6c 6f 61 64 69 6e |tic while loadin| 00000790 67 20 74 68 65 20 66 69 6c 6d 2e 20 20 20 20 20 |g the film. | 000007a0 20 20 20 2a 2f 0a 2f 2a 20 45 61 63 68 20 61 72 | */./* Each ar| 000007b0 72 61 79 20 68 61 73 20 34 30 20 65 6c 65 6d 65 |ray has 40 eleme| 000007c0 6e 74 73 2c 20 73 6f 20 74 68 65 20 68 69 67 68 |nts, so the high| 000007d0 65 73 74 20 69 6e 64 65 78 20 66 6f 72 20 61 6e |est index for an| 000007e0 79 20 6f 66 20 74 68 65 20 20 20 20 20 20 20 2a |y of the *| 000007f0 2f 0a 2f 2a 20 61 72 72 61 79 73 20 73 68 6f 75 |/./* arrays shou| 00000800 6c 64 20 62 65 20 33 39 2e 20 20 20 20 20 20 20 |ld be 39. | 00000810 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000830 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 0a 20 | */.. | 00000840 20 66 6f 72 20 28 69 3d 30 3b 20 69 3c 6d 61 78 | for (i=0; i<max| 00000850 5f 66 72 61 6d 65 73 3b 20 69 2b 2b 29 0a 20 20 |_frames; i++). | 00000860 7b 20 70 72 69 6e 74 66 28 22 50 6c 65 61 73 65 |{ printf("Please| 00000870 20 65 6e 74 65 72 20 74 68 65 20 65 78 70 6f 73 | enter the expos| 00000880 75 72 65 20 6f 66 20 66 72 61 6d 65 20 25 64 2e |ure of frame %d.| 00000890 5c 6e 22 2c 69 29 3b 0a 20 20 20 20 73 63 61 6e |\n",i);. scan| 000008a0 66 28 22 25 64 22 2c 26 65 78 70 6f 73 75 72 65 |f("%d",&exposure| 000008b0 5b 69 5d 29 3b 0a 20 20 20 20 70 72 69 6e 74 66 |[i]);. printf| 000008c0 28 22 50 6c 65 61 73 65 20 65 6e 74 65 72 20 74 |("Please enter t| 000008d0 68 65 20 61 70 65 72 74 75 72 65 20 73 65 74 74 |he aperture sett| 000008e0 69 6e 67 20 66 6f 72 20 66 72 61 6d 65 20 25 64 |ing for frame %d| 000008f0 2e 5c 6e 22 2c 69 29 3b 0a 2f 2a 20 54 68 65 20 |.\n",i);./* The | 00000900 61 70 65 72 74 75 72 65 20 69 73 20 72 65 61 64 |aperture is read| 00000910 20 61 73 20 61 20 66 6c 6f 61 74 69 6e 67 20 70 | as a floating p| 00000920 6f 69 6e 74 20 6e 75 6d 62 65 72 2c 20 61 6e 64 |oint number, and| 00000930 20 74 68 65 20 69 6e 74 65 67 65 72 20 61 6e 64 | the integer and| 00000940 20 20 2a 2f 0a 2f 2a 20 74 68 65 20 66 69 72 73 | */./* the firs| 00000950 74 20 64 65 63 69 6d 61 6c 20 70 6c 61 63 65 20 |t decimal place | 00000960 70 61 72 74 73 20 6f 66 20 74 68 65 20 6e 75 6d |parts of the num| 00000970 62 65 72 20 61 72 65 20 68 65 6c 64 20 69 6e 20 |ber are held in | 00000980 65 6c 65 6d 65 6e 74 73 20 7a 65 72 6f 20 2a 2f |elements zero */| 00000990 0a 2f 2a 20 61 6e 64 20 6f 6e 65 20 6f 66 20 74 |./* and one of t| 000009a0 68 65 20 61 72 72 61 79 2e 20 20 20 20 20 20 20 |he array. | 000009b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 000009d0 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 20 20 20 | */. | 000009e0 20 73 63 61 6e 66 28 22 25 66 22 2c 26 64 61 74 | scanf("%f",&dat| 000009f0 75 6d 29 3b 0a 20 20 20 20 61 70 65 72 74 75 72 |um);. apertur| 00000a00 65 5b 69 5d 5b 30 5d 20 3d 20 28 69 6e 74 29 64 |e[i][0] = (int)d| 00000a10 61 74 75 6d 3b 0a 20 20 20 20 61 70 65 72 74 75 |atum;. apertu| 00000a20 72 65 5b 69 5d 5b 31 5d 20 3d 20 28 64 61 74 75 |re[i][1] = (datu| 00000a30 6d 20 2d 20 61 70 65 72 74 75 72 65 5b 69 5d 5b |m - aperture[i][| 00000a40 30 5d 29 20 2a 20 31 30 3b 0a 20 20 20 20 70 72 |0]) * 10;. pr| 00000a50 69 6e 74 66 28 22 50 6c 65 61 73 65 20 65 6e 74 |intf("Please ent| 00000a60 65 72 20 74 68 65 20 6c 6f 63 74 69 6f 6e 20 66 |er the loction f| 00000a70 6f 72 20 66 72 61 6d 65 20 25 64 2e 5c 6e 22 2c |or frame %d.\n",| 00000a80 69 29 3b 0a 20 20 20 20 67 65 74 63 68 61 72 28 |i);. getchar(| 00000a90 29 3b 0a 2f 2a 20 54 68 65 20 67 65 74 73 28 29 |);./* The gets()| 00000aa0 20 66 75 6e 63 74 69 6f 6e 20 72 65 61 64 73 20 | function reads | 00000ab0 61 20 6c 69 6e 65 20 6f 66 20 74 65 78 74 20 66 |a line of text f| 00000ac0 72 6f 6d 20 74 68 65 20 6b 65 79 62 6f 61 72 64 |rom the keyboard| 00000ad0 20 69 6e 74 6f 20 61 20 20 20 20 20 2a 2f 0a 2f | into a */./| 00000ae0 2a 20 73 74 72 69 6e 67 2e 20 49 74 20 74 61 6b |* string. It tak| 00000af0 65 73 20 61 73 20 61 6e 20 61 72 67 75 6d 65 6e |es as an argumen| 00000b00 74 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 |t a pointer to t| 00000b10 68 65 20 73 74 72 69 6e 67 2e 20 54 68 69 73 20 |he string. This | 00000b20 63 6f 75 6c 64 20 20 20 2a 2f 0a 2f 2a 20 62 65 |could */./* be| 00000b30 20 77 72 69 74 74 65 6e 20 27 26 62 75 66 66 65 | written '&buffe| 00000b40 72 5b 30 5d 27 2c 20 73 69 6e 63 65 20 74 68 61 |r[0]', since tha| 00000b50 74 20 69 73 20 77 68 65 72 65 20 77 65 20 77 61 |t is where we wa| 00000b60 6e 74 20 74 68 65 20 73 74 72 69 6e 67 20 74 6f |nt the string to| 00000b70 20 20 20 20 2a 2f 0a 2f 2a 20 67 6f 2c 20 62 75 | */./* go, bu| 00000b80 74 20 74 68 69 73 20 69 73 20 6a 75 73 74 20 61 |t this is just a| 00000b90 20 70 6f 69 6e 74 65 72 20 74 6f 20 65 6c 65 6d | pointer to elem| 00000ba0 65 6e 74 20 7a 65 72 6f 20 6f 66 20 74 68 65 20 |ent zero of the | 00000bb0 61 72 72 61 79 20 61 6e 64 20 73 6f 20 20 20 20 |array and so | 00000bc0 2a 2f 0a 2f 2a 20 73 6f 20 63 61 6e 20 61 6c 73 |*/./* so can als| 00000bd0 6f 20 62 65 20 77 72 69 74 74 65 6e 20 27 62 75 |o be written 'bu| 00000be0 66 66 65 72 27 2e 20 20 20 20 20 20 20 20 20 20 |ffer'. | 00000bf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000c00 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 20 | */. | 00000c10 20 20 20 67 65 74 73 28 62 75 66 66 65 72 29 3b | gets(buffer);| 00000c20 0a 2f 2a 20 73 74 72 6c 65 6e 28 29 20 72 65 74 |./* strlen() ret| 00000c30 75 72 6e 73 20 74 68 65 20 6c 65 6e 67 74 68 20 |urns the length | 00000c40 6f 66 20 61 20 73 74 72 69 6e 67 2e 20 49 74 20 |of a string. It | 00000c50 64 6f 65 73 20 5f 6e 6f 74 5f 20 69 6e 63 6c 75 |does _not_ inclu| 00000c60 64 65 20 74 68 65 20 20 20 20 2a 2f 0a 2f 2a 20 |de the */./* | 00000c70 74 65 72 6d 69 6e 61 74 69 6e 67 20 7a 65 72 6f |terminating zero| 00000c80 20 62 79 74 65 2e 20 20 20 20 20 20 20 20 20 20 | byte. | 00000c90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000cb0 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 6c 65 6e | */. len| 00000cc0 20 3d 20 73 74 72 6c 65 6e 28 62 75 66 66 65 72 | = strlen(buffer| 00000cd0 29 3b 0a 2f 2a 20 53 65 74 20 75 70 20 74 68 65 |);./* Set up the| 00000ce0 20 70 6f 69 6e 74 65 72 20 69 6e 20 70 6c 61 63 | pointer in plac| 00000cf0 65 5b 69 5d 20 74 6f 20 70 6f 69 6e 74 20 74 6f |e[i] to point to| 00000d00 20 61 6e 20 61 72 65 61 20 62 69 67 20 65 6e 6f | an area big eno| 00000d10 75 67 68 20 74 6f 20 68 6f 6c 64 20 2a 2f 0a 2f |ugh to hold */./| 00000d20 2a 20 74 68 65 20 73 74 72 69 6e 67 20 6a 75 73 |* the string jus| 00000d30 74 20 69 6e 70 75 74 2e 20 4e 6f 74 65 3a 20 31 |t input. Note: 1| 00000d40 29 20 73 69 7a 65 6f 66 28 63 68 61 72 29 20 69 |) sizeof(char) i| 00000d50 73 20 61 73 73 75 6d 65 64 20 74 6f 20 62 65 20 |s assumed to be | 00000d60 6f 6e 65 2c 20 73 6f 20 2a 2f 0a 2f 2a 20 6e 6f |one, so */./* no| 00000d70 74 20 6e 65 65 64 65 64 20 69 6e 20 74 68 65 20 |t needed in the | 00000d80 6d 61 6c 6c 6f 63 28 29 20 73 74 61 74 65 6d 65 |malloc() stateme| 00000d90 6e 74 20 61 6e 64 20 32 29 20 74 68 65 20 62 6c |nt and 2) the bl| 00000da0 6f 63 6b 20 6d 75 73 74 20 62 65 20 6f 6e 65 20 |ock must be one | 00000db0 20 20 20 20 2a 2f 0a 2f 2a 20 62 79 74 65 20 6c | */./* byte l| 00000dc0 6f 6e 67 65 72 20 74 68 61 6e 20 74 68 65 20 6e |onger than the n| 00000dd0 75 6d 62 65 72 20 6f 66 20 63 68 61 72 61 63 74 |umber of charact| 00000de0 65 72 73 20 69 6e 20 74 68 65 20 73 74 72 69 6e |ers in the strin| 00000df0 67 20 74 6f 20 61 6c 6c 6f 77 20 66 6f 72 20 20 |g to allow for | 00000e00 2a 2f 0a 2f 2a 20 74 68 65 20 74 65 72 6d 69 6e |*/./* the termin| 00000e10 61 74 69 6e 67 20 7a 65 72 6f 2e 20 20 20 20 20 |ating zero. | 00000e20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000e40 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 20 | */. | 00000e50 20 20 20 70 6c 61 63 65 5b 69 5d 20 3d 20 6d 61 | place[i] = ma| 00000e60 6c 6c 6f 63 28 6c 65 6e 2b 31 29 3b 0a 2f 2a 20 |lloc(len+1);./* | 00000e70 73 74 72 63 70 79 28 29 20 63 6f 70 69 65 73 20 |strcpy() copies | 00000e80 6f 6e 65 20 73 74 72 69 6e 67 20 74 6f 20 61 6e |one string to an| 00000e90 6f 74 68 65 72 20 73 74 72 69 6e 67 20 2d 20 77 |other string - w| 00000ea0 68 69 63 68 20 63 61 6e 6e 6f 74 20 62 65 20 64 |hich cannot be d| 00000eb0 6f 6e 65 20 20 20 2a 2f 0a 2f 2a 20 69 6e 20 43 |one */./* in C| 00000ec0 20 62 79 20 61 20 73 69 6d 70 6c 65 20 73 74 72 | by a simple str| 00000ed0 69 6e 67 31 3d 73 74 72 69 6e 67 32 20 63 6f 6d |ing1=string2 com| 00000ee0 6d 61 6e 64 2e 20 49 6e 20 74 68 69 73 20 63 61 |mand. In this ca| 00000ef0 73 65 2c 20 74 68 65 20 73 74 72 69 6e 67 20 20 |se, the string | 00000f00 20 20 2a 2f 0a 2f 2a 20 70 6f 69 6e 74 65 64 20 | */./* pointed | 00000f10 74 6f 20 62 79 20 74 68 65 20 70 6f 69 6e 74 65 |to by the pointe| 00000f20 72 20 27 62 75 66 66 65 72 27 20 69 73 20 63 6f |r 'buffer' is co| 00000f30 70 69 65 64 20 74 6f 20 74 68 65 20 6d 65 6d 6f |pied to the memo| 00000f40 72 79 20 62 6c 6f 63 6b 20 20 20 20 20 20 2a 2f |ry block */| 00000f50 0a 2f 2a 20 70 6f 69 6e 74 65 64 20 74 6f 20 62 |./* pointed to b| 00000f60 79 20 74 68 65 20 70 6f 69 6e 74 65 72 20 27 70 |y the pointer 'p| 00000f70 6c 61 63 65 5b 69 5d 27 2e 20 54 68 65 20 63 6f |lace[i]'. The co| 00000f80 70 79 69 6e 67 20 73 74 6f 70 73 20 77 68 65 6e |pying stops when| 00000f90 20 61 20 20 20 20 20 20 20 20 2a 2f 0a 2f 2a 20 | a */./* | 00000fa0 74 65 72 6d 69 6e 61 74 69 6e 67 20 7a 65 72 6f |terminating zero| 00000fb0 20 69 73 20 65 6e 6f 75 6e 74 65 72 65 64 20 69 | is enountered i| 00000fc0 6e 20 74 68 65 20 73 74 72 69 6e 67 20 70 6f 69 |n the string poi| 00000fd0 6e 74 65 64 20 74 6f 20 62 79 20 62 75 66 66 65 |nted to by buffe| 00000fe0 72 2e 20 20 20 20 2a 2f 0a 20 20 20 20 73 74 72 |r. */. str| 00000ff0 63 70 79 28 70 6c 61 63 65 5b 69 5d 2c 62 75 66 |cpy(place[i],buf| 00001000 66 65 72 29 3b 0a 20 20 7d 0a 0a 2f 2a 20 54 68 |fer);. }../* Th| 00001010 65 20 6e 65 78 74 20 6c 6f 6f 70 20 70 72 69 6e |e next loop prin| 00001020 74 73 20 6f 75 74 20 61 6c 6c 20 74 68 65 20 76 |ts out all the v| 00001030 61 6c 75 65 73 20 74 68 61 74 20 77 65 20 68 61 |alues that we ha| 00001040 76 65 20 6a 75 73 74 20 69 6e 70 75 74 2e 20 20 |ve just input. | 00001050 20 20 20 20 2a 2f 0a 20 20 66 6f 72 20 28 69 3d | */. for (i=| 00001060 30 3b 20 69 3c 6d 61 78 5f 66 72 61 6d 65 73 3b |0; i<max_frames;| 00001070 20 69 2b 2b 29 0a 20 20 7b 20 70 72 69 6e 74 66 | i++). { printf| 00001080 28 22 45 78 70 6f 73 75 72 65 20 25 64 20 77 61 |("Exposure %d wa| 00001090 73 20 74 61 6b 65 6e 20 61 74 20 25 73 5c 6e 22 |s taken at %s\n"| 000010a0 2c 69 2c 70 6c 61 63 65 5b 69 5d 29 3b 0a 20 20 |,i,place[i]);. | 000010b0 20 20 69 66 20 28 65 78 70 6f 73 75 72 65 5b 69 | if (exposure[i| 000010c0 5d 20 3e 20 30 29 0a 20 20 20 20 7b 20 70 72 69 |] > 0). { pri| 000010d0 6e 74 66 28 22 77 69 74 68 20 61 6e 20 65 78 70 |ntf("with an exp| 000010e0 6f 73 75 72 65 20 6f 66 20 25 64 20 22 2c 65 78 |osure of %d ",ex| 000010f0 70 6f 73 75 72 65 5b 69 5d 29 3b 20 7d 20 65 6c |posure[i]); } el| 00001100 73 65 0a 20 20 20 20 7b 20 70 72 69 6e 74 66 28 |se. { printf(| 00001110 22 77 69 74 68 20 61 6e 20 65 78 70 6f 73 75 72 |"with an exposur| 00001120 65 20 6f 66 20 31 2f 25 64 20 22 2c 2d 65 78 70 |e of 1/%d ",-exp| 00001130 6f 73 75 72 65 5b 69 5d 29 3b 20 7d 0a 20 20 20 |osure[i]); }. | 00001140 20 70 72 69 6e 74 66 28 22 61 6e 64 20 61 6e 20 | printf("and an | 00001150 61 70 65 72 74 75 72 65 20 6f 66 20 25 64 2e 25 |aperture of %d.%| 00001160 64 2e 5c 6e 5c 6e 22 2c 61 70 65 72 74 75 72 65 |d.\n\n",aperture| 00001170 5b 69 5d 5b 30 5d 2c 61 70 65 72 74 75 72 65 5b |[i][0],aperture[| 00001180 69 5d 5b 31 5d 29 3b 0a 20 20 7d 0a 2f 2a 20 53 |i][1]);. }./* S| 00001190 69 6e 63 65 20 6d 61 69 6e 28 29 20 69 73 20 74 |ince main() is t| 000011a0 65 63 68 6e 69 63 61 6c 6c 79 20 61 20 66 75 6e |echnically a fun| 000011b0 63 74 69 6f 6e 2c 20 77 65 20 73 68 6f 75 6c 64 |ction, we should| 000011c0 20 72 65 74 75 72 6e 20 7a 65 72 6f 20 66 72 6f | return zero fro| 000011d0 6d 20 20 20 20 2a 2f 0a 2f 2a 20 69 74 20 74 6f |m */./* it to| 000011e0 20 72 65 61 73 73 75 72 65 20 74 68 65 20 6d 61 | reassure the ma| 000011f0 63 68 69 6e 65 20 74 68 61 74 20 65 76 65 72 79 |chine that every| 00001200 74 68 69 6e 67 20 68 61 73 20 67 6f 6e 65 20 77 |thing has gone w| 00001210 65 6c 6c 2e 20 44 6f 6e 27 74 20 20 20 20 20 20 |ell. Don't | 00001220 20 2a 2f 0a 2f 2a 20 77 6f 72 72 79 20 61 62 6f | */./* worry abo| 00001230 75 74 20 74 68 69 73 20 66 6f 72 20 74 68 65 20 |ut this for the | 00001240 6d 6f 6d 65 6e 74 2e 20 20 20 20 20 20 20 20 20 |moment. | 00001250 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00001260 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a | */.| 00001270 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a | return 0;.}.| 0000127e