I've done a project in which I needed to calculate the multiplications of very large numbers using LinkedList. However, even though I get the right answers I got an error message.
Process finished with exit code -1073741819 (0xC0000005)
This happens whenever one of the numbers is really large. I've looked at old posts but I couldn't find anything similar to my situation.
Here are the example outputs.
Example with error code Example without error code
I store the numbers in a LinkedList as digits. So, every node has a digit and there shouldn't be any issue about int/long thing I guess but I couldn't find what makes this. When I debug the code, I get the error pointer at the end of the code, where there is no code. Debug
I hope I explained my problem properly, thanks in advance.
CodePudding user response:
The error code 0xC0000005
means "access violation" in Microsoft Windows, which is the equivalent of a Linux "segmentation fault".
The problem is probably the following code:
char num1[] = "";
[...]
printf( "Num1: " );
gets( num1 );
This will cause a buffer overflow if the user enters anything more than an empty line. That is because the array num1
only has room for a single character (which is already needed for the null terminating character).
I suggest that you use the following code instead:
char num1[100];
[...]
printf( "Num1: " );
fgets( num1, sizeof num1, stdin );
The code related to num2
has the same problem.
I strongly suggest that you read this:
Why is the gets function so dangerous that it should not be used?