I have made a simple program using the GMP library that is the start of a factoring program I'm making. Basically, it just factors a number (n) up to a bound, which is either 4000000000 or the sqrt of the number, whichever is smaller. In this example the number being factored is 1000.

I get three errors, all of which are the same: error C2107: illegal index, indirection not allowed.

I'm pretty sure it has to do with the array but I don't know how to fix it.

Here's the source code, I put a comment before the error lines

Thanks in advance!Code:#include <iostream> #include <gmp.h> using namespace std; int main() { mpz_t n, k, var, N, N2, array, hold; mpz_init (n); mpz_init (k); mpz_init (hold); mpz_init (var); mpz_init (N); mpz_init (N2); mpz_set_ui (n, 1000); mpz_set_ui (k, 2); mpz_array_init (array, 4000000000, 1); mpz_sqrt (N, n); if (mpz_cmp_ui (N, 4000000000) == -1) mpz_set_ui (N2, 4000000000); else mpz_set (N2, N); while (mpz_cmp (k, N2) == -1) { //the following line has the first two errors if (mpz_sgn (array[k]) == 0) { mpz_cdiv_q (hold, n, k); if (mpz_sgn (hold) == 0) { cout << k << " * " << hold << "; "; mpz_set (var, k); while (var <= N2) { mpz_add (var, var, k); //the following line has the next error mpz_set (array[var], 0); } } } mpz_add_ui (k, k, 1); } mpz_clear (n); mpz_clear (k); mpz_clear (var); mpz_clear (N); mpz_clear (N2); return 0; }

MadCow