DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   String operations (http://www.daniweb.com/forums/thread34867.html)

peter_budo Nov 5th, 2005 5:33 pm
String operations
 
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
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

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 :
WORD - DEFINITION. 2nd DEFINITION if used
what we get is of course
WORD - DEFINITION
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?

Daishi Nov 7th, 2005 8:42 am
Re: String operations
 
http://www.daniweb.com/techtalkforums/thread19956.html


All times are GMT -4. The time now is 11:30 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC