/**************************************************************************** * * Function Name : main * Description : Demonstration basic string concepts * Returns : Success or Failure * ****************************************************************************/ int main() { /* Initialising an array */ char str[SIZE] = " Technologies Pvt Ltd., Gurgaon Bangalore Chennai."; /* This mus the done at the end. Uncomment this line and comment the above line. The program crashes because strtok is trying to change a const */ /* Initializing an pointer to a consant */ //char *str = " Technologies Pvt Ltd., Gurgaon Bangalore Chennai."; char *words[MAX]; /* Array of pointers to store the tokenized words */ int no_of_words = 0; /* Stores the total number of words */ str_ret ret_value = SUCCESS; /* Return value from function */ /* Initializing the array of pointers */ memset(words,0,MAX); printf("Original string before tokenization is %s\n", str); /* Function call to tokenize the words */ ret_value = store_words(str, words, &no_of_words); if(FAILURE == ret_value) /* Error handling */ { printf("Function Failed\n"); exit(FAILURE); } /* Displaying the tokenized words */ ret_value = display_words(words, no_of_words); /* Observe the output here. The challenge with strtok is that it modifies the input string. It is better to write our own tokenizer */ printf("Original string after tokenization is %s\n", str); return 0; }
Dict::Dict(string f) : INIT_SIZE(50) { //ifstream reference; // decided to make this a member reference.open(f.c_str()); // makes the file stream point to the file //cout << "Dict object successfully instantiated" << endl; words = new string[INIT_SIZE]; phrases = new string[INIT_SIZE]; sentences = new string[INIT_SIZE]; store_words(); // scan for and store all unique words store_phrases(); store_sentences(); // same, but for sentences that end with a period qsort(words, word_count, sizeof(string), compare); qsort(phrases, phrase_count, sizeof(string), compare); qsort(sentences, sentence_count, sizeof(string), compare); //for(int i = 0; i < word_count; i++) // //cout << words[i] << endl; //for(int i = 0; i < phrase_count; i++) //cout << phrases[i] << endl; //for(int i = 0; i < sentence_count; i++) // //cout << sentences[i] << endl; }//constructor