| | |
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
however if you do that table will strangly get mess up. To prevent this behaviour you have to do following
Took some time to find out.
Reading is finish, data in hash table we sort them now is time export them.
Format : what we get is of course
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?
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
C Syntax (Toggle Plain Text)
1st_def = 1st_def + 2nd_def
C Syntax (Toggle Plain Text)
1st_def = 1st_def + "\n" + 2nd_def
Reading is finish, data in hash table we sort them now is time export them.
Format :
C Syntax (Toggle Plain Text)
WORD - DEFINITION. 2nd DEFINITION if used
C Syntax (Toggle Plain Text)
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?
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- JS opacity menu Problems In IE - rare (HTML and CSS)
- code currupt (C++)
- ArrayList to multi-dimensional string array (C#)
- Beginner with C++ and goofy run time problem with DBL Linked List (C++)
- Concept to fruition - the chronicle of a new site (Growing an Online Community)
- Loading and accessing 2 Dimensional tables (C++)
- String Object Immutable Confusion (Java)
- Help with fstream (C++)
Other Threads in the C Forum
- Previous Thread: Bank Management System
- Next Thread: Problems reading from files
| Thread Tools | Search this Thread |
* adobe api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o ide inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






