|CSC 161||Grinnell College||Fall, 2013|
|Imperative Problem Solving and Data Structures|
The goal of this lab is to introduce basic character, and string, input and output using files.
Write a small program that counts all the characters in a file. Your output should give you how many letters, spaces, newlines, and other characters there are.
Write a program that will count how many words there are in your file.
Bioinformatics solves problems in biology with the use of computer science.
The file mouse_gene has genetic data from a mouse. This file contains information about four different genetic regions, each beginning with a tag, such as > AB000913 1. Unfortunately, having all these regions in the same file is not particularly helpful, and it would be useful to divide the initial file into four smaller and distinct files, one for each genetic region.
Write a C program that will take in this file as an input and then produce 4 files as an output. Each of the output files should contain a tag such as > AB000913 1 that indicates different smaller genetic regions, and the genetic regions to which the tag corresponds.
Write a small C program called mycat.c that reads a text file and prints its contents to stdout. You will likely find the C library functions fgets and fputs (or puts) useful. Recall that, in contrast with scanf, fgets returns NULL when it encounters the end of the file. For this initial exercise, you may hard code the name of some file that already exists in your account as the input file. You may assume that no line in the input file will contain more than 256 characters. Don't forget to close the file when you are done!
The output from your program should be similar to what you would get by typing "cat infile" at the shell prompt, assuming a file named infile exists in your directory.
Modify your program so that it reads the name of the file from the keyboard. The program should give a useful error message if the specified file does not exist.
Hint: Use the online manual to determine how fopen works if the specified file is not present. Recall that you can type man fopen to reference the online manual for this function.
Development of laboratory exercises is an interative process. Prof. Walker welcomes your feedback! Feel free to talk to him during class or stop by his office.