944,078 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 8400
  • C RSS
Nov 5th, 2005
0

String operations

Expand Post »
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?
Similar Threads
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Daishi is offline Offline
80 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: A Function Plotter using Turbo C++ Graphics
Next Thread in C Forum Timeline: Problems reading from files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC