473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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 3072
fhmm
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
Banfa
9,065 Expert Mod 8TB
Have a go yourself, then we'll help iron out the glitches.

Expand|Select|Wrap|Line Numbers
  1. open read 
  2. do
  3.   read file line
  4.   issolate words on the line (using pointers or strtok)
  5.   for each word
  6.     if this is the first time the word has appeared
  7.       add word to list of found words with a recurance count of 1
  8.     else
  9.       find word in list of words and increment it's recurance count
  10.     endif
  11.   endfor
  12. while(you haven't reached the end of the file)
  13.  
  14. Generate output
  15.  
Sep 23 '06 #3
fhmm
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
Banfa
9,065 Expert Mod 8TB
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
  1. char line[250];
  2. char *pSpace;
  3. ifstream infile("<filename>");
  4.  
  5. infile.getline(line, sizeof line);
  6.  
  7. pSpace = strchr(line, ' ');
  8.  
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

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: R. Heydenreich | last post by:
Hi all, I try to create an index page from a document. The idea behind is to collect a certain word and list it with *all* occurences in the document, like foo .... 12, 23, 45 bar .... 2, 5,...
8
by: DrNoose | last post by:
Hi! I'm writing a program that is supposed to read a line of input, count the words and the number of occurrences of each letter. Then it should prints the number of occurrences of each letter...
1
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working...
0
by: slacker | last post by:
I have to write a program that reads in a text file word by word and calculates how many times each word appears in the file. * I have to use dynamic array of pointers to structures to accumulate...
3
by: utab | last post by:
Dear all, I tried to solve the occurence problem: to find the distinct occurences of a word in an input. I know that I could use map and other STD lib functions. I tried to do it the hard way. I...
3
by: Nhd | last post by:
I have a question which involves reading from cin and counting the number of words read until the end of file(eof). The question is as follows: Words are delimited by white spaces (blanks,...
4
by: bigbagy | last post by:
Notes The programs will be compiled and tested on the machine which runs the Linux operating system. V3.4 of the GNU C/C++ compiler (gcc ,g++) must be used. A significant amount coding is...
7
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27...
2
by: gdarian216 | last post by:
I am writting a code that opens a file and gets the file name from a command line argument. I then open an output stream to print results of functions in a separate file. I have written a function...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.