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
- Use isspace to determine if a character is white space or not
Assume we have file named fun.txt that contains the following:
Computer sciences classes are great!
Even though I spend all my time doing homework :(
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.
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
Name of the file
- N will always be at least 1
- If N is greater than the number of lines in the file, all of the lines in the file should be displayed
- You may assume that no line is longer than 100 characters
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
- My editor automatically added 1 newline character to the end of most of the test files but does not display them. Your editor may or may not display them but do be aware that they are there.
Example. Assume the file meme.txt contains the following
../tail.out meme.txt 1
../tail.out meme.txt 2
../tail.out meme.txt 10