name score
The name may contain any number of words with any amount of white space between them. No word in a name may be a number. The score is a floating point number (use a double). Example input files are input1, input2 and input3 in the lab2 directory.
Maxmin should take an input file on standard input, and print out the maximum and minimum score. If standard input is not in the proper form, maxmin can do anything.. You should try out the example executable in /home/plank/cs140/Fall-2004/labs/lab2/answers:
UNIX> maxmin < input1 Max: 0.714000 Min: 0.377000 UNIX> maxmin < input2 Max: 68.430000 Min: 35.900000 UNIX> maxmin < input3 Max: 74.580000 Min: 69.210000 UNIX>
You should also try this on other input files that you make up. Does your executable work if the input file has no lines?
You may assume that no line in your input file is greater than 1000 characters. Words may be any size up to 1000 characters.
(Hint: use scanf("%s", ...) to read in words, and then use sscanf(s, "%lf", ...) to see if it is a score.)
UNIX> maxminname < input1 Max: 0.714000 New York Yankees Min: 0.377000 Detroit UNIX> maxminname < input2 Max: 68.430000 Ted McLellan & Brad Vander Zanden Min: 35.900000 MULTIPLE-NAME UNIX> maxminname < input3 Max: 74.580000 Chip Beck Min: 69.210000 David Duval UNIX>
Hint: you should have four character arrays in your program; all of them should be 1000 characters:
A picture is simply a two-dimensional array of pixels. In pgm files, a pixel is a grey value between 0 and 255. Zero is black, and 255 is white. Everything in between is grey.
Pgm files have a specific format. (Actually, I've tweaked them a little to make this easier for you). It is composed of words. The first word is ``P2''. Then the next two words define the number of pixels in the picture -- first is the number of columns in the two-dimensional array, and then the number of rows. The next word is the number 255. So, if you look at the beginning of jsp.pgm, you'll see:
UNIX> head jsp.pgm P2 252 267 255 37 44 37 37 44 37 44 44 44 37 44 44 48 48 48 44 37 34 33 34 37 33 34 37 48 44 44 44 48 44 44 44 44 53 44 44 37 44 53 53 49 44 41 37 41 41 33 33 29 26 26 29 29 33 37 37 44 48 53 53 57 53 57 61 64 69 69 81 81 77 81 81 73 77 72 48 37 33 33 33 37 37 48 44 33 22 22 25 22 22 14 14 14 14 22 22 22 22 22 22 22 22 22 22 26 22 22 22 22 18 22 18 22 18 18 18 22 26 22This means that jsp.pgm is a 267 * 252 array of pixels. After the 255 come all the pixels. First, the top row, then the next row, etc. Note that the ASCII formatting of the file doesn't mean anything -- there could be one pixel per line and the file would still be a legal pgm file. In jsp.pgm above, the first 252 pixels are those in the top row, then the next 252 are in the second row, and so on. There will be a total of 267*252 = 67284 pixels. After the last pixel, the file ends.
Before you go any further, create a PGM file of your own -- make it 10x10 and give the pixels any value you want. Take a look at it with display. Cool, no?
Now, your first pgm program should take a pgm file on standard input, and create a pgm file on standard output that is the negative of the input file. Call this program neg.
Note, you don't need to call malloc() with this program. Just read in the first four words, print them out, then print out 255 minus each pixel. You can put a newline after each pixel if you want to make it really easy (this is what I did). Check out the output, and see how it looks:
UNIX> neg < jsp.pgm > jspneg.pgm UNIX> display jspneg.pgm
You'll have to use malloc() for this one. Read in the first four words, and then malloc() a row's worth of pixels. Then, for each row, read in the row and write it out backwards. Test it out!
You'll have to do a little more now. Allocate an array of row (int *)'s. Then initialize each one of those (int *)'s by calling malloc() to allocate an array of column ints. Read each row of pixels into one of these arrays, and then print them out backwards.
When you're done, clean up all your stray pgm files -- they are large and with 60 students, that's a lot of wasted disk space. If you want to keep the images, use display to turn them into gif or jpg images to save space.