429,401 Members | 793 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

# counting the percentage and occurence of each identical word in input file

 P: 6 I am an intermediate programmer and i tried to solve the following programme but with no success the programme is a simple text analyzer that read an input file and cumpute the occurence and percentage of each similar word .for example lets consider the following input file. "The for structure totals the elements of the array one row at the time. The outer for structure begins by setting row of the array to 0." the analysis of the programme shold be the following: Word Frequency % the 6 22.25% for 2 7.41% structure 2 7.41% totals 1 3.70% elements 1 3.70% of 2 7.41% Array 2 7.41% one 1 3.70% row 2 7.41% at 1 3.70% time 1 3.70% outer 1 3.70% begins 1 3.70% by 1 3.70% setting 1 3.70% to 1 3.70 % 0 1 3.70% Total words 27 Sep 23 '06 #1
4 Replies

 P: 6 I am an intermediate programmer and i tried to solve the following programme but with no success the programme is a simple text analyzer that read an input file and cumpute the occurence and percentage of each similar word .for example lets consider the following input file. "The for structure totals the elements of the array one row at the time. The outer for structure begins by setting row of the array to 0." the analysis of the programme shold be the following: Word///////////////// Frequency ////////////// % the///////////// 6 ///////////// 22.25% for//////////// 2 //////////// 7.41% structure///////// 2 /////////// 7.41% totals /////////// 1 ////////// 3.70% elements /////// 1 ///////// 3.70% of ////// 2 //////// 7.41% Array//////// 2 ////// 7.41% one//////// 1 //////// 3.70% row/////////// 2 //////// 7.41% at/////////// 1 ////// 3.70% time/////////// 1 ///// 3.70% outer ////////// 1 //// 3.70% begins /////// 1 /// 3.70% by ////// 1 // 3.70% setting ///// 1 ///// 3.70% to ///// 1 ///// 3.70 % 0 //// 1 //// 3.70% Total words////////////////////////// 27 Sep 23 '06 #2

 Expert Mod 5K+ P: 8,916 Have a go yourself, then we'll help iron out the glitches. Expand|Select|Wrap|Line Numbers open read  do   read file line   issolate words on the line (using pointers or strtok)   for each word     if this is the first time the word has appeared       add word to list of found words with a recurance count of 1     else       find word in list of words and increment it's recurance count     endif   endfor while(you haven't reached the end of the file)   Generate output   Sep 23 '06 #3

 P: 6 can you tell me how to copy the text from an array to a pointer to acharacter because i have use infile.getline and it does not accept pointers to charachter parameters so,i have used array. thank you, Sep 23 '06 #4

 Expert Mod 5K+ P: 8,916 I think you are a little confused. The would be no need to copy to or even have a pointer to char to hold your data. Your array is all you need so Expand|Select|Wrap|Line Numbers char line[250]; char *pSpace; ifstream infile("");   infile.getline(line, sizeof line);   pSpace = strchr(line, ' ');   In this code line is an array of char. However just using line by itself in the code provides a pointer to that array. line has type char *, but it is not a pointer. I have a pointer in my code to hold the location of the first space in the line. Sep 23 '06 #5