![]() |
|
#1
|
|||
|
|||
I have a segmentation error in my programmy program consists of two parts.class word is already tested and works fine yet, class Sentence isn't tested yet.I had tried to test in this main function the addWord function and the << operator which means print.however,at the end of the program runtime I get a segmentation fault.
this is the main: CPP / C++ / C Code:
this is the class Word.h CPP / C++ / C Code:
the class Word.cpp CPP / C++ / C Code:
the class Sentence.h CPP / C++ / C Code:
the class Sentence.cpp CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: I have a segmentation error in my programOne problem that I saw immediately is that when you allocate memory for a word, you allocate strlen() number of bytes. You actually need strlen()+1 in order to hold the '\0' NULL-terminating character.
|
|
#3
|
|||
|
|||
Re: I have a segmentation error in my programAnother things i saw from this code is passing array as arguments,
CPP / C++ / C Code:
This is a ugly style which i always avoided from. I rather will do , CPP / C++ / C Code:
Please correct me if i worng. I hope this help. __________________
Linux is the best OS in the world. |
|
#4
|
||||
|
||||
Re: I have a segmentation error in my programJust to give you a little background (I haven't looked at your code yet) a segmentation fault occurs when you have a pointer that is null being used, it is uninitialized, or you have deleted it twice (yes this can occur). Or you have an array that is accessing something outside of the memory that has been allocated to it. Check your code to see if any of these have occurred.
Hope this helps a bit. |
|
#5
|
|||
|
|||
Re: I have a segmentation error in my programQuote:
If you define the string 'size' to be 80 and then use that name as an argument to a function it will be replaced by the preprocessor and you should see an error similar to Quote:
CPP / C++ / C Code:
By convention, macros (or defined constants) are usually all capital letters. Also, there is nothing wrong with passing only an array as an argument, especially if the size is not needed. Of course, the part about the array is just my opinion - you are free to dismiss. |
|
#6
|
|||
|
|||
Re: I have a segmentation error in my programthank you for your help,the problem was with my destructor.
|
Recent GIDBlog
Master?s Degree by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Employee program segmentation error. | ShadowTH | CPP / C++ Forum | 1 | 08-Dec-2007 13:28 |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 10:13 |
| Help with a complex program | lordfuoco | CPP / C++ Forum | 5 | 24-Jun-2006 06:03 |
| Dynamic memory, loops, and segmentation faults | ubergeek | CPP / C++ Forum | 2 | 07-May-2005 16:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The