Hello,
This function was copied into my code, which was compiled without error/warning, but when executed there is always Segmentation fault at the end after the output (which seems correct!):
Program received signal SIGSEGV, Segmentation fault.
strlen () at ../sysdeps/x86_64/strlen.S:106
106 ../sysdeps/x86_64/strlen.S: No such file or directory.
The problem line has been highlighted. Code for the whole program is attached. I used type cast to suppress the warnings at compiling without full understanding.
Can someone explain the error for me, and show me the correct fix?
Thanks a lot!
Thanks achenle, you said it is not a string , but it seems the program has done what I expected except the "segmentation fault" error. Can you please show me the fix, if possible?
Murphy! I made the change, but the error still there!
Running the code with Qt creator it seems limiting the bound in the outer loop:
for (j = 0; j < 22; j++)
allows the code to run with out any memory violation errors. This might be a clue to the problem ( not sure what the code does )..
Edit: Opps! when I change the outer loop bound to 22 the code seems to run without any memory access violations on Fedora 23 using g++ version: 5.3.1 20151207 . Not sure what the problem is on your end. I would find which loop indexes the program crashes for you and then trace the code from there using a debugger.
Thanks cman!
Finally the problem was found to be the third last entry of my str[], for which the comma was missing!
*str[]={......,
"......cagt",
"....acgatc" //Here the comma was left out!
"...ggggcta",
"....acgcat"}
};
Each single string was 500 char long wrapped in two lines but concatenated with a "\n" in the middle. The missing comma make the third last string 1000 char long, which violated the macro definition:
#define WORD_BUF_SIZE 512
However, I'd like to know your way to debug I would find which loop indexes the program crashes for you! Thanks a lot!
That's just how I would do the debugging. Once I knew the index where the program crashed , you could use a debugger to trace forward at the beginning of the loop(s) to find what caused the crash ( this way you can eliminate a lot of code as the problem - as long as something in the prior code did not cause the problem in the first place, in which case you could go backward in the indexes to find what the problem is ).