class - C++ find words with first and last same letter and sort them in alphabetical order -


i can't make program reads file words ( there no limit of words or length them ) same first letter , last. use class , object , first of can't make reading them

#include <iostream> #include <string> #include <sstream> #include <fstream>  using namespace std; class texts{  public:     void realding(string &all);     void searching(string &text, char *word); }; int main() {      texts a;     string text; char word[40];     a.reading(text);     a.searching(text, word);     system("pause");   }  void texts::reading(string &all) {     string temp;     ifstream read("text.txt");     while (getline(read, temp)) { += temp; += "\n"; }     cout << all;  }  void texts::searching(string &text, char *word) {     int = 0;     int j = 0;     int letters = 0;     int zodz = 0;     int index = 0;     while (1)     {          if (text[i] == ' ' || text[i] == '\0')         {              zodz++;             if (text[0] == text[i - 1])             {                 letters = j;                 (int l = 0; l < letters; l++)                 {                     //cout << text[l];                 }                 j = 0;             }             if (text[i + 1 - j] == text[i - 1])             {                 letters = j;                 (int l = - j; l < letters; l++)                 {                 //  cout << text[l];                 }                 j = 0;             }           }          if (text[i] == '\0') break;            else         i++;                                    j++;      } } 

i can't make read file... text.txt looks

asdfa su egze hah ktis faf 

and how later when selected words first , last same letter assign array, later sort them in alphabetical order. if helps me.

reading file:

std::ifstream in(nameoffile); std::string word;  while (in >> word) //will stop when word can't read. bad file or end of file {     // word } 

find word same first , last letter

if (word[0] == word[word.length() - 1]) {     // word } 

note not handle words capitalized letters. not find "mom". crash on empty words. both have trivial fixes.

assign word array

array[index++] == word; 

this assumes want advance index after inserting array. please note program behave poorly if array overfilled. if allowed assignment, please consider using std::vector.

sorting array

std::sort(array, array + index); 

this assumes allowed use std::sort. again, if possible use std::vector in place of array. index assumed value of index adding example above after of adding has been done. if not allowed use std::sort ask question. it's lengthy topic.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -