So my code compiles on Dev C++ but when it runs, it gives a blank output screen for a few seconds then the program terminates. The code on Dev shows no errors or warnings. It works perfectly on VS. I have tried re-installing Dev but that doesn't work. I know Dev is outdated but i'm forced to check my code on it since its a project and will be checked and graded on Dev. I did not feel like posting the whole code since it is around 400 lines but since it might or might not help in understanding the problem, i have attached it. I don't know which part might cause this issue so i've attached the whole thing. I hope you don't mind. This is my first post here so if I've made any mistakes in asking a question please let me know. Thanks.
Asked
Active
Viewed 171 times
0
-
2Even dev c++ has debugger, learn how to debugging by dev c++ should help. Put breakpoints on suspicious lines and check for value. – Louis Go Jul 01 '20 at 05:13
-
[Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons). – molbdnilo Jul 01 '20 at 05:14
-
So it loops until the end of file has been reached and all contents of the file have been input – user13554582 Jul 01 '20 at 06:13
-
Yes ill try debugging. have to learn it first. I suspect this has something to with incorrect memory access or illegal read/write although there are no such warnings shown – user13554582 Jul 01 '20 at 06:15
-
@user13554582 No, you're trying to read beyond the end of the file, and your code has undefined behaviour. – molbdnilo Jul 01 '20 at 06:32
-
@LouisGo It says 'program received signal SIGSEGV, segmentation fault'. Can you help me out here please – user13554582 Jul 01 '20 at 06:49
-
@molbdnilo oh i see. How do i make it stop at the end of the file? – user13554582 Jul 01 '20 at 06:52
-
Follow my link. Read a good book. – molbdnilo Jul 01 '20 at 06:53
1 Answers
0
Thank you so much to @LouisGo and @molbdnilo for the help. I've found the reason for the segmentation error in Dev C++ through debugging. This part:
*hashArray = NULL;//SET ARRAY INDEXES TO NULL
was the problem. Dev C++ doesn't allow initializations in this way while VS does. So I had to initialize it this way:
for(int i=0; i<20; i++)
{
hashArray[i]=NULL;
}
It works fine now.

user13554582
- 1
- 1