Requirement 1
Write a program called wcount.c that counts all the words in a given file
- Name your executable wcount.out
- The name of the file to count the words in will be passed on the command line
- For this problem we will define a word as a series of 1 or more non-whitespace
characters
Use isspace to determine if a character is white space or not
Examples
Assume we have file named fun.txt that contains the following:
Computer sciences classes are great!
Even though I spend all my time doing request :(
1 | ../wcount fun.txt |
Requirement 2
Write a program called perimeter.c that calculates the perimeter of a polygon.
- Name your executable perimeter.out
- The points of the polygon will be stored in a file and this file will be passed on the command line arguments
- The file itself will be a binary file containing integers
- The first integer in the file is the number of points contained in the file
- The remaining integers are the points, with the first integer being the x coordinate and the second integer being the y coordinate.
- There is an edge between each adjacent point and between the first point and the last point
- Each file contains at least 3 points
- The perimeter of a polygon is the sum of the lengths of all of its edges
Use a double to store your perimeter and report the perimeter to the nearest 2 decimal points.
You MUST store your points in a struct to receive credit for this problem.
As an aside the example tests do not form actual polygons but assume that they do.
Example. Assume that there is a file called example.txt. It will store the following information but in binary form. This example is just to give you a visualization of the data.
Requirement 3
Write a program called tail.c that prints out the last N lines of a given file
- Name your executable tail.out
- Arguments to your program will be passed on the command line in the following order
- For an additional challenge try to solve the problem where there is no limit on the length of a line
- My solution to dealing with any length lines involved using the functions ftell and fseek.
- There is no limit to the number of lines in a file
- Some lines may only contain the newline character, these still count as a line
1
2
3
4../tail.out meme.txt 10
It
is
over 9000!!!
1 | ../tail.out meme.txt 2 |