Google Answers Logo
View Question
 
Q: reading from a file. ( No Answer,   3 Comments )
Question  
Subject: reading from a file.
Category: Computers > Programming
Asked by: phelsva-ga
List Price: $20.00
Posted: 06 May 2003 13:44 PDT
Expires: 08 May 2003 17:45 PDT
Question ID: 200291
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;
}

Request for Question Clarification by dogbite-ga on 06 May 2003 14:50 PDT
Hi phelsva-ga,

  I am interested in answering your question, but
  to answer it well I think it will require more
  time and effort that the average amount of effort 
  and time associated with a $17.00 question.  Please 
  see this link that discusses pricing:

https://answers.google.com/answers/pricing.html

  The work would take me at least one hour, so I
  feel $50 is more appropriate.  If you would like
  me to answer, I will do it for $50.  Otherwise
  you can wait for another researcher to answer.

               dogbite-ga
Answer  
There is no answer at this time.

Comments  
Subject: Re: reading from a file.
From: magnesium-ga on 06 May 2003 20:55 PDT
 
Has Google Answers turned into eBay, with researchers naming exact
amounts for which they will answer questions? While a general
statement about the appropriateness of a price may be called for, I
find it rather crass when researchers give precise dollar amounts, as
has been done here. Seems rather like extortion, somehow, sort of like
"I'm holding your answer hostage. If you ever want to see your answer
alive again, gimme fifty bucks. Otherwise I will cut off one of your
answer's fingers every hour and send it to you in a brown, unmarked
envelope."
Subject: Re: reading from a file.
From: dogbite-ga on 06 May 2003 21:09 PDT
 
Hi magnesium-ga,

  I'm sorry my request for clarification
  made you feel like I was holding this
  question hostage.  I will reaffirm that
  I am only one of many researchers and
  that any other researcher is free to
  answer this question.

  At the same time, I think it is helpful
  to let customers know when a researcher is
  willing and able to answer a question,
  yet at a higher price.  That is why I
  pointed phelsva-ga to the pricing guidelines.

  Ultimately every customer is free to 
  price their questions as they choose.
  The question is not held hostage -- any
  researcher might answer at the selected price.

                 dogbite-ga
Subject: Re: reading from a file.
From: phelsva-ga on 07 May 2003 17:41 PDT
 
I'm prepared to tip anyone if the question is answered to my satisfaction

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy