String operations

Reply

Join Date: Dec 2004
Posts: 4,190
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 483
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

String operations

 
0
  #1
Nov 5th, 2005
Explanation is a bit long so please bear with me, solution is short :lol:
We got an assigngment from uni to create word dictionary program to read an external file where each line consist of WORD and DEFINITION separated by empty space. If some word exists more than once add other definitions append. Please use static hash table and sort datat in alphabetic order:evil:
Fine we will do it. :mrgreen:
Using getline we get word and then definition plus this automaticaly delete '\0' character and next function insert them in hash table. As long word does not repeat everything it's fine. But if program find that word already exists in table we should join definitions as
  1. 1st_def = 1st_def + 2nd_def
however if you do that table will strangly get mess up. To prevent this behaviour you have to do following

  1. 1st_def = 1st_def + "\n" + 2nd_def
Took some time to find out.
Reading is finish, data in hash table we sort them now is time export them.
Format :
  1. WORD - DEFINITION. 2nd DEFINITION if used
what we get is of course
  1. WORD - DEFINITION
  2. 2nd DEFINITION

OK, we have to delete new line character in order to get proper out put. We store definition in temporary variable, then search this variable for new line character, if found replace it with one empty space ( " " ). Well search and replacement work perfect but when outputing everything get mess up. AGAIN!!!

Question
Can anybody provide me with explanation what is happening over there and how should I stop this bad manners of my program?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 80
Reputation: Daishi is an unknown quantity at this point 
Solved Threads: 2
Daishi Daishi is offline Offline
Junior Poster in Training

Re: String operations

 
0
  #2
Nov 7th, 2005
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC