0% found this document useful (0 votes)
63 views1 page

CSCD 240 Lab 7: To Turn in

The document provides instructions for a C programming lab assignment to create functions for opening input and output files. Students are asked to create a fileutil.c and fileutil.h that contain functions to open files, including: openInputFile to open a file for reading; promptOpenInputFile to prompt the user for a file and open for reading; openOutputFile to open a file for writing; and promptOpenOutputFile to prompt the user for a file and open for writing. Students will then create a test program cscd240Lab7.c that uses these functions to read from and write to files, and tests invalid file name handling. The final submission is a zip file containing the C files, header, Makefile

Uploaded by

theomega76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views1 page

CSCD 240 Lab 7: To Turn in

The document provides instructions for a C programming lab assignment to create functions for opening input and output files. Students are asked to create a fileutil.c and fileutil.h that contain functions to open files, including: openInputFile to open a file for reading; promptOpenInputFile to prompt the user for a file and open for reading; openOutputFile to open a file for writing; and promptOpenOutputFile to prompt the user for a file and open for writing. Students will then create a test program cscd240Lab7.c that uses these functions to read from and write to files, and tests invalid file name handling. The final submission is a zip file containing the C files, header, Makefile

Uploaded by

theomega76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CSCD 240

Lab 7
1. In Java you most likely created a FileUtil class. Lets emulate that same concept in C.
Create fileutil.c and fileutil.h

Create an openInputFile function that takes a char array as the parameter, representing
the filename. The function will open that file for reading and return the FILE pointer. If
the file does not exist you must reprompt until the file exists and is open.

Create promptOpenInputFile function that prompts the user for the filename, the
function will open that file for reading and return the FILE pointer. If the file does not
exist it will continue to prompt for the filename.

Create an openOutputFile function that takes a char array as the parameter, representing
the filename. The function will open that file for writing and return the FILE pointer. If
the file cant be opened the function will print an error message and exit the program.

Create promptOpenOutputFile function that prompts the user for the filename, the
function will open that file for writing and return the FILE pointer.

Create a test program named cscd240Lab7.c that does the following:

o Tests openInputFile and openOutputFile by passing the name of the files


o Read the strings in and write them to the output file
o Closes both files
o Tests promptOpenInputFile and promptOpenOutputFile by prompting for the
file names. Dont forget to test for an invalid file name.
o Read a set of numbers in from the input file and write that set of numbers to the
output file.
o Close both files.

TO TURN IN:

A zip file containing


All .c files
fileutil.h
A Makefile with a target of lab7
An output file name cscd240lab7out.txt

Name your zip your last name first letter of your first name lab7.zip (Example steinerslab7.zip)

You might also like