Question
INSTRUCTOR SUPPLIED DRIVER FILE: #define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE #include #include #include C2A6E4_List-Driver.h #define FILENAME TestFile1.txt FILE *OpenFile(const char *fileName); List *CreateList(FILE *fp); List *PrintList(const List
INSTRUCTOR SUPPLIED DRIVER FILE:
#define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE
#include
#include "C2A6E4_List-Driver.h"
#define FILENAME "TestFile1.txt"
FILE *OpenFile(const char *fileName); List *CreateList(FILE *fp); List *PrintList(const List *head); void FreeList(List *head);
int main(void) { FILE *fp = OpenFile(FILENAME); List *head = CreateList(fp);
fclose(fp); FreeList(PrintList(head));
return EXIT_SUCCESS; } #endif
INSTRUCTOR SUPPLIED HEADER FILE:
#ifndef C2A6E4_LIST_DRIVER_H #define C2A6E4_LIST_DRIVER_H // You may #include this file in your file(s) as necessary. //****************************************************************************
// Format of each list node... typedef struct List { struct List *next; // pointer to the next list node char *str; // pointer to the string represented int count; // # of occurrences of this string } List;
#endif
TEST TEXT FILE:
The number-sign or "stringizing" operator (#) converts macro parameters (after expansion) to string constants. It is used only with macros that take arguments. If it precedes a formal parameter in the macro definition, the actual argument passed by the macro invocation is enclosed in quotation marks and treated as a string literal. The string literal then replaces each occurrence of a combination of the stringizing operator and formal parameter within the macro definition.
White space preceding the first token of the actual argument and following the last token of the actual argument is ignored. Any white space between the tokens in the actual argument is reduced to a single white space in the resulting string literal. Thus, if a comment occurs between two tokens in the actual argument, it is reduced to a single white space. The resulting string literal is automatically concatenated with any adjacent string literals from which it is separated only by white space.
Thank you for all your help! I really appreciate it.
C2A6E4 (8 points - Program) Exclude any existing source code files that may already be in your IDE project and add two new ones, naming them C2A6E4_OpenFile.c and C2A6E4_List.c. Also add instructorsupplied source code fie: C2A6E4 List-Driver.h and C2A6E4_main-Driver.c. Do not write a main function! main already exists in the instructor-supplied implementation file and it will use the code you write. Regarding data type List, which is used in this exercise.... List is a typedef'd data type that is defined in instructor supplied header file C2A6E4 List-Driver.h Any file that uses this data type must include this header file using #include. File C2A6E4 OpenFile.c must contain a function named OpenFile. 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 fileName in the read-only text mode. If the open foils an error message is output to stderr and the program is terminated with an error exit code. The error message must mention the name of the failing file. Return: a pointer to the open file it the open succeeds; otherwise, the function does not return File C2A&E4_List.c must contain functions named CreateList, PrintList, FreeList. CreateList syntax List Createlist(FILE *fp); Parameter: fp-a pointer to an open text file containing zero or more whitespace-separated words (string) Synopsis: Creates a singly-linked list from strings it reads from the text file represented by parameter fp. Each ist node represents a unique case-dependent string and the number of times it occurred in the file. This is the simplest algorithm and is recommended: 1. Attempt to read a string from the file. If successful: A. Searoh the list for that string- i. I found: a. Inorement the node's string count. ii. elce: a. Alcoate a new node, and then b. allocate memory the string linoluding 10), point de's ohar pointer to that allocation, and copy the string into it. c. Set the node's string count to 1. d. Push the node onto the list. B. Repeat from step 1. 2. Eise, return the let's "head" pointer. Return: the list's head pointer. Example: - Number of node: created if file contains: Fly fly! 12 nodes) Fly Fly! 12 nodes) Fly fly ! (3 nodes) Fly Fly ! 12 nodes) PrintList syntax List PrintList(const List head); Parameter: head - the head pointer to the previously described list Synopsis: Displays a non-sorted table of the date attributes from the list whose head pointer is passed to it, starting at the head of the list. The display must be in the format illustrated below, in which the first character in each string is aligned and the least significant digits of the occurrence counts are aligned. There are no blank lines between entries. For example: the 107 ea White 25 ea White? 4 ea if 16 ea Return: head Freelist syntax void FreeList(List "head); Parameter: head - the head pointer to the previously described list Synopsis: Frees all dynamic allocations in the list. Return: vold Restrictions: The Freelist function must col no functions or macros other than the standard library free function, which it may call as needed. General Exercise Requirements: Never dynamically alocate space for a new node or string until you have first: 1. read a string from the text file, and then 2. searched the existing list for it and not found it there. Use no dynamic allocations other than those necessary for each node and its string. Alocate space for a node and its string separately, allocating for the node before the string. Allocate exactly the right amount of memory needed for each string, including its 10. Do not sort the list. Do not attempt to read the entire input file into your program at once. Test the program on instructor-supplied data file Testfile.fact, which must be placed in the program's "working directory". Submitting your solution Send al four source code files to the assignment checker with the subject line C2A6E4_ID, where ID is your 9-character UCSD student ID See the course dooument titled "How to Prepare and Submit Assignments" for additional exercise formatting, submission, and assignment oheoker requirements. Hints: Include each string's null terminator when allocating memory and copying. When deleting a node always free its string before freeing the node itself. Freeing the node first results in a memory leakStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started