I am working on a C method to find the inverse of a number mod n, and it works perfectly fine when for example I call this method with 6.0 and 65537.0, it gives me the correct result, even when showing a warning for dereferencing the pointer, however when I call it with a = 3.0 and n = 177408180034551.0 visual studio break in the line origNums[0] = n; and gives me error
0xC0000005: Access violation writing location 0x00000000.
I understand that with smaller arrays like size 5 or what not, I could simply initialize my array with something like origNums = {1,2,3,4,5} but because of the size of my modulo that is simply not possible for a human to write and putting a for loop to fill the arrays would give the same access violation. So what other solution is there to this issue? And more importantly why is there no warning for nums[0] = rightVal; ? if they both had a warning it would seem like it is a common issue but in visual studio only the first assignment is underlined with a warning.
double inverseModN(double a, double n)
{
double* nums = (double*) malloc((n) * sizeof(double));
double* origNums = (double*)malloc((n) * sizeof(double));
*more var declarations*
origNums[0] = n;
nums[0] = rightVal;
*rest of the code*
}
I tried smaller mod values and they work perfectly fine, so it wasn't until I tried larger mods that this error came about, how can I fix this error?