Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are 2 files here to be coded in C. I understand that I am supposed to get user input and load the sentence the

There are 2 files here to be coded in C. I understand that I am supposed to get user input and load the sentence the user gives into a buffer. I do not understand how to index by array and index by ptr. Or how the first file is supposed to be the header file so that the first program works. These are the instructions: You should store the input characters into a character array as your working buffer. A word is defined as any sequence of non-whitespace characters. The input will terminate with an EOF if there are less than 2048 characters, but your program shall accept no more than 2048. Your program shall record the beginning and end of each word in the buffer and use the buffer itself as the storage for the content of each word. The report needs to be generated from the buffer and the index to the words in the buffer. You are not allowed to declare or use any global variables. All variables must be locally scoped. You may however add any additional #define directives you deem needed or helpful. To highlight the relation of pointers and arrays, you will actually implement two methods for doing this work. One method will use array syntax and indexes to index each word. The other method should be functionally equivalent but implemented with pointer syntax. Need help coding these 2 files! file1: #ifndef STRING_INDEX_HEADER #define STRING_INDEX_HEADER #define BUFFER_SIZE 2048 #define WORD_LIMIT 100 #define NOT_FOUND -1 #define WD_BGN 0 #define WD_END 1 // Prototypes /* initialize_buffer: Fills the given array with characters from stdin until either EOF or 2048 characters have been loaded. Returns the total number of characters loaded and -1 if no characters loaded. */ /******************************************************** Functions that work with arrays ********************************************************/ /* index_buffer_by_array: Indexes the beginning and end of each unique word (string of non-whitespace characters). The index is a list of beginning and ending array indexes for each unique word found. Duplicate words are counted in w_counts array. Returns the total number of unique words found in the character buffer. */ int index_buffer_by_array(const char buffer[], int index[][2], int w_counts[] ); /* find_word_by_array: Determines if the word in buf[] beginning at index word_beg is already indexed. A word terminates with the first whitespace character. Returns the index number for the word if found, otherwise returns NOT_FOUND. */ int find_word_by_array(int word_beg, const char buf[], int index[][2]); /* print_report_by_array: Prints to stdout a report giving the word index number, offset of first letter from beginning of the buffer, the word count, and the word itself. This function expects index to be an array of array indexes for the beginning and end of each word. Example output for buffer containing the characters in quotes "all the all" 0( 0): 2 all 1( 4): 1 the */ void print_report_by_array(const char buf[], int index[][2], int counts[], int word_cnt){ /******************************************************* Functions that work with pointers ********************************************************/ /* index_buffer_by_ptr: Indexes the beginning and end of each unique word (string of non-whitespace characters). The index is a list of beginning and ending char pointers for each unique word found. Duplicate words are counted in w_counts array. Returns the total number of unique words found in the character buffer. */ int index_buffer_by_ptr(const char * buf, const char * index[][2], int word_counts[] ){ /* find_word_by_ptr: Determines if the word in beginning at the char * beg is already indexed. A word terminates with the first whitespace character. Returns the index number for the word if found, otherwise returns NOT_FOUND. */ int find_word_by_ptr(const char * beg, const char * index[][2]){ /* print_report_by_ptr: Prints to stdout a report giving the word index number, offset of first letter from beginning of the buffer, the word count, and the word itself. This function expects index to be an array of char pointers for the beginning and end of each word. Example output for buffer containing the characters in quotes "all the all" 0( 0): 2 all 1( 4): 1 the */ void print_report_by_ptr(const char * buf, const char * index[][2], int counts[], int word_cnt){ #endif file2: // Program description // Author: /***************************************************************************** * * Psuedocode here: * * *****************************************************************************/ #include #include #include "string_index.h" int main(void) { // variable declartaions // initialize storage /* ***** DO NOT CHANGE ANY CODE BEYOND THIS POINT IN main() ****** */ initialize_buffer(buffer); words_found = index_buffer_by_ptr(buffer, word_index, word_counts); print_report_by_ptr(buffer, word_index, word_counts, words_found); words_found = index_buffer_by_array(buffer, word_index_array, word_counts); print_report_by_array(buffer, word_index_array, word_counts, words_found); } // end main /* ***** YOUR FUNNCTION DEFINTIONS BELOW ***** */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

2. How can competencies be used in employee development?

Answered: 1 week ago