#define ALLOW_INSTRUCTOR_CODE /*************************************************************************** *************************************************************************** ****** BEFORE BEGINNING OR TURNING IN THIS EXERCISE IT IS EXTREMELY ****** ****** IMPORTANT THAT YOU READ, FULLY UNDERSTAND, AND ADHERE TO THE ****** ****** REQUIREMENTS STATED IN THE DOCUMENT TITLED, "ASSIGNMENT ****** ****** SUBMISSION REQUIREMENTS", DOWNLOADABLE FROM THE COURSE WEB ****** ****** SITE. ****** *************************************************************************** **************************************************************************/ /*************************************************************************** ************* C/C++ Programming 2: Assignment 3 - Exercise 4 ************* ********* BEGIN EXERCISE REQUIREMENT - THIS MUST BE A "C" PROGRAM ********* *************************************************************************** (4 points) Often programs must read text files in which data fields are separated by arbitrary delimiters. For example, such a file might contain multiple lines with variable-length comma-separated fields such as: John Jones,2345 Boring St., Anytown, USA Mary Lu,876-1/2 Back Road Dr.,BC, Mexico Write functions OpenFile and ParseStringFields: OpenFile syntax: FILE *OpenFile(const char *fileName); Parameters: fileName - a pointer to the name of the file to be opened Synopsis: Opens the file named in in the read-only text mode. If the open fails an error message is output to stderr and the program is terminated with an error exit code. Return: a pointer to the open file if the open succeeds; otherwise, the function does not return. ParseStringFields syntax: void ParseStringFields(FILE *fp); Parameters: fp - a pointer to a file open in a readable text mode Synopsis: Reads input from the text file in , treating the characters "AEIOUaeiou\n" as delimiters, and uses the strtok function to find each delimited field and display it on a separate line. Any leading whitespace that might be present at the beginning of any field is skipped. Whitespace is as defined by the isspace function. Return: void For example, the file contents listed above, the display would be: J hn J n s,2345 B r ng St., nyt wn, S M ry L ,876-1/2 B ...etc. * You may assume that no delimited field will be wider than 255 characters. * Do not attempt to read an entire file into your program at once. * Use the isspace function to detect whitespace. * Test your program on input file "TestFile3.txt", downloaded from the course web site. Hint: * Place input test file "TestFile3.txt" in the appropriate default location described in the "FILE LOCATION QUESTIONS AND ANSWERS" section of the "ASSIGNMENT SUBMISSION REQUIREMENTS" document. *************************************************************************** ************************ END EXERCISE REQUIREMENT ************************* **************************************************************************/ /*************************************************************************** * BEFORE PRINTING THIS ASSIGNMENT TO TURN IN, DELETE THIS COMMENT AND * EVERYTHING ABOVE IT. **************************************************************************/ /* * TODO: * REPLACE THIS COMMENT WITH YOUR TITLE BLOCK. */ /* * TODO: * REPLACE THIS COMMENT WITH YOUR C CODE, PLUS ANYTHING NECESSARY TO * SUPPORT MY TEST CODE BELOW. DO NOT INCLUDE ANY UNNEEDED HEADER FILES! */ /*************************************************************************** * BEFORE PRINTING THIS ASSIGNMENT TO TURN IN, DELETE THIS COMMENT AND * EVERYTHING BELOW IT. **************************************************************************/ /* ***** Change nothing below this comment without instructor permission. **** * Everything that follows was written to help test/verify your code. You * do not need to understand the details of my code to write yours! */ #ifdef ALLOW_INSTRUCTOR_CODE #define FILENAME "TestFile3.txt" int main(void) { FILE *fp = OpenFile(FILENAME); ParseStringFields(fp); fclose(fp); return EXIT_SUCCESS; } #endif