data compression help!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 6
Reputation: lazyboy292 is an unknown quantity at this point 
Solved Threads: 0
lazyboy292 lazyboy292 is offline Offline
Newbie Poster

data compression help!

 
0
  #1
Feb 2nd, 2008
i have to write a code for compression of lines with redundancies. You are supposed to enter a line of code--for example(YES I CAN! YES I CAN! YES I CAN!) and your output should look like this (3YES3I3CAN3!) so the codes job is to count the number of times a word or character appears. i really appreciate the help. thank you very much
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: data compression help!

 
0
  #2
Feb 2nd, 2008
OK, so what is your question?

Maybe start with reading a line and breaking it into words.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 6
Reputation: lazyboy292 is an unknown quantity at this point 
Solved Threads: 0
lazyboy292 lazyboy292 is offline Offline
Newbie Poster

Re: data compression help!

 
0
  #3
Feb 2nd, 2008
i just dont know how to break up the string into smaller parts in order to count the words
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: data compression help!

 
0
  #4
Feb 2nd, 2008
Well how do you read a line?

Consider writing a loop which looks for space characters.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 6
Reputation: lazyboy292 is an unknown quantity at this point 
Solved Threads: 0
lazyboy292 lazyboy292 is offline Offline
Newbie Poster

Re: data compression help!

 
0
  #5
Feb 2nd, 2008
so something like..

for(int i=0; i<line.length();i++)
{
if(line[i]==' ')
*just have something increment to store it?*
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: data compression help!

 
0
  #6
Feb 3rd, 2008
Yes, something like that.

If 'word' is say char word[20] , then words might be char words[10][20]
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 6
Reputation: lazyboy292 is an unknown quantity at this point 
Solved Threads: 0
lazyboy292 lazyboy292 is offline Offline
Newbie Poster

Re: data compression help!

 
0
  #7
Feb 3rd, 2008
okay. so after i separate the words into a 2D array, then houw would i compare those two arrays?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: data compression help!

 
0
  #8
Feb 3rd, 2008
Take a look at strcmp() .
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,859
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 55
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso

Re: data compression help!

 
0
  #9
Feb 3rd, 2008
Or in C++, why bother with what one may call 'messy' character arrays, when there is a 'nice' string type at our disposal. Look at the .substr() method of strings. I recommend looking at the first word of the sentence, finding the next instance of that letter, checking for equality with sub strings from the first letter to the second instance of the same and the substring from the second instance plus the distance from the first to the second, etc. Know what I mean? If that fails try for the next instance of the first letter until you pass the mid-way point of the string. Then go to the second letter ... sounds like fun, huh?
Last edited by twomers; Feb 3rd, 2008 at 6:58 pm.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 6
Reputation: lazyboy292 is an unknown quantity at this point 
Solved Threads: 0
lazyboy292 lazyboy292 is offline Offline
Newbie Poster

Re: data compression help!

 
0
  #10
Feb 3rd, 2008
haha i have no clue what you mean. but i do know how to use string compare. and i am totally f-ed in my a. lolz. this is due tomorrow and i'm clueless to how to do this
Last edited by lazyboy292; Feb 3rd, 2008 at 9:24 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC