once again, i need help to meet the deadline at work. I have provided
most of the program already (the header file, driver file and main
program). It runs well with no errors on my microsoft visual C++
compiler. Please read the question well and what i need done to the
program I already have. I would be most grateful if I could receive
this program by early friday 05/09/2003 or ealier.
This project will require you to read in a sorted file
of
words, load each word into a node of a linked list and then tranverse
the
linked list to produce a report that prints the following information
- The total number of words in the file
- The total number of distinct words in the file
- The total number of words in the file that begin with a
vowel(a,e,i,o,u) character
- The total number of words in a file that begin with a constant
character
- The total number of hyphenated words in the file
- The total number of words in a file with 5 or less characeters
- The total number of words in a file with more than 5 and less than
11
characeters
- The total number of words in a file with more than 10 and less than
14
characeters
- The total number of words in a file with 14 or more characeters
- The total number of distinct words with 5 or less characeters
- The total number of words in a file with more than 5 and less than
11
characeters
- The total number of words in a file with more than 10 and less than
14
characeters
- The total number of words in a file with 14 or more
characeters
You should build a dynamic linked list data structure and read each
distinct word from the quotation below into a node of the linked list.
At
each nod, you should retain data elements to contain the word, count
the
number of occurrences of the word, and store the size of the word.
After
you finish the linked list, transverse it to produce the report.
Should be
in API source code(custom header file, function library, and main
driver
file)
"In your hands, my fellow citizens, more than mine, will rest the
final
success or failure of our course. Since this country was founded, each
generation of Americans has been summoned to give testimony to its
national
loyalty. The graves of young Americans who answered the call to
service
surround the globe.
Now the trumpet summons us again--not as a call to bear arms,
though
arms we need--not as a call to battle, though embattled we are-- but a
call
to bear the burden of a long twilight struggle, year in and year out,
"rejoicing in hope, patient in tribulation"--a struggle against the
common
enemies of man: tyranny, poverty, disease and war itself.
Can we forge against these enemies a grand and global alliance,
North
and South, East and West, that can assure a more fruitful life for all
mankind? Will you join in that historic effort?
In the long history of the world, only a few generations have
been
granted the role of defending freedom in its hour of maximum danger. I
do
not shrink from this responsibility--I welcome it. I do not believe
that
any of us would exchange places with any other people or any other
generation. The energy, the faith, the devotion which we bring to this
endeavor will light our country and all who serve it--and the glow
from
that fire can truly light the world.
And so, my fellow Americans: ask not what your country can do for
you--ask what you can do for your country."
/* header file */
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
void FileError(char *, char *);
void nomemory(void);
void CheckInputError(int, int);
/* driver file */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* File I/O error function*/
void FileError( char *operation, char *file_name)
{
fprintf(stderr, "Program is terminating due to the following
condition:\n");
if(strcmp(operation, "open")== 0)
{
fprintf(stderr, "Error: invalid open on file: %s.]n", file_name);
fprintf(stderr, "File is empty, missing, or corrupted.\n");
exit(301);
}
else
if(strcmp(operation, "close") == 0)
{
fprintf(stderr, "Error: invalid close on file: %s.\n", file_name);
exit(302);
}
else
if(strcmp(operation, "read") == 0)
{
fprintf(stderr, "Error: invlaid read on file: %s.\n", file_name);
fprintf(stderr, "File is empty or corrupted.\n");
exit(303);
}
else
if(strcmp(operation, "input") == 0)
{
fprintf(stderr, "Error: There are data problems on the input
record.\n");
fprintf(stderr, "Error: See report output fo explanation of the
error.\n");
exit(304);
}
else
if(strcmp(operation, "write") == 0)
{
fprintf(stderr, "Error: invalid write on file: %s.\n", file_name);
exit(305);
}
else
{
fprintf(stderr, "Error:invalid call to File_error function,
operation = %s, file_name = %s.\n", operation,file_name);
exit(306);
}
return;
}
/*Print an error condition on memory allocation error*/
void nomemory(void)
{
fprintf(stderr,"\nERROR: Not enough memory to run this program.\n");
exit(200);
}
/* function to check for invalid input values for interactive modules
*/
void CheckInputError(int result, int expected)
{ if(result != expected)
{ fprintf(stderr, "\nInvalid input value(s). Program is
terminating.\n");
exit(100);
}
return;
}
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "errorfun.h"
#define TRUE 1
#define FALSE 0
#define MAX_NODES 50
#define IS_FULL(ptr) (!(ptr))
#define IS_EMPTY(ptr) (!(ptr))
struct ELEMENT
{ char word[30];
};
typedef struct LIST_NODE *list_ptr;
typedef struct LIST_NODE
{ struct ELEMENT node_data;
list_ptr link;
}linked_list;
list_ptr front= NULL;
/* function prototypes */
void create_list(void);
void visit_node(list_ptr);
void traverse_list(list_ptr);
void search_list(struct ELEMENT*);
void initialize_element(struct ELEMENT*);
void delete_node(list_ptr, list_ptr, struct ELEMENT*);
/* Main Function */
int main(void)
{ extern list_ptr front;
list_ptr pnode[MAX_NODES];
struct ELEMENT new_data *pelem;
pelem= &new_data;
initialize_element(pelem);
create_list();
strcpy(pelem->word, "bat");
pnode[0] = insert_node(front, NULL, pelem);
strcpy(pelem->word, "cat");
pnode[1] = insert_node(pnode[0], NULL, pelem);
strcpy(pelem->word, "sat");
pnode[2] = insert_node(pnode[1], NULL, pelem);
strcpy(pelem->word, "vat");
pnode[3] = insert_node(pnode[2], NULL, pelem);
traverse_list(pnode[0]);
return 0;
}
/* Function to initialize an element's component values */
void initialize_element(struct ELEMENT *pelement)
{ strcpy(pelement->word, " ");
}
/* Function to create an empty list. */
void create_list(void)
{ extern list_ptr front;
front=(list_ptr) malloc(sizeof(linked_list));
if IS_FULL(front) nomemory();
initialize_element(&front->node_data));
front->link=NULL;
return;
}
/* Function to visit a node of the list. */
void visit_node(list_ptr ptr)
{ printf("%s\t", ptr->node_data.word);
}
/* Traverse the linked list (recursive function). */
void traverse_list(list_ptr ptr)
{ if(ptr)
{ visit_node(ptr);
traverse_list(ptr->link);
}
return;
}
/* Search the linked list for an elemant (iterative function). */
int search_list(struct ELEMENT *psearch_data)
{ extern list_ptr ptr=front;
list_ptr ptr=front;
int result=FALSE;
while(ptr && result == FALSE)
{ if(strcmp(ptr->node_data.word, psearch_data->word)==0)
result=TRUE;
else
ptr=ptr->link;
}
return result;
}
/* Delete a node from the list. */
void delete_node(list_ptr delete_node, list_ptr head, list_ptr tail)
{ int result= FALSE;
struct ELEMENT *psearch_data = NULL;
psearch_data= &(delete_node->node_data);
result= search_list(psearch_data);
if (result==FALSE)
fprintf(stderr, "Error: node not deleted: it does not exist in the
list.\n");
else
{
head->link=tail;
free(delete_node);
}
return;
}
/* Insert a node into the list. */
list_ptr insert_node(list_ptr head, list_ptr tail, struct ELEMENT
*pnewnode)
{ int result= FALSE;
list_ptr ptr=NULL;
result=search_list(pnewnode);
if (result==TRUE)
{ fprint(stderr, "Error: node not inserted: it already exists in the
list.\n");
ptr= NULL;
}
else
{ ptr= (list_ptr) mallic(sizeof(linked_list));
if IS_FULL(ptr) nomemory();
/* Losd and link the node. */
ptr->node_data= new_data;
ptr->link = tail;
head->link = ptr;
}
return ptr;
} |