I use this program to store a mpz value but when I add a 0 ( 400000000000000000000000000000000000000 instead of 40000000000000000000000000000000000000 -> 38 0s instead of 37) I get
free(): double free detected in tcache 2
Aborted (core dumped)
#include <iostream>
#include <gmpxx.h>
#include <vector>
using namespace std;
int main(const int argc, const char * const argv[])
{
char *str = (char*)malloc(sizeof(char)*1024);
mpz_class l;
l = 40000000000000000000000000000000000000_mpz;
mpz_set_str(l.get_mpz_t(), str, 10);
cout << endl << str;
return 0;
}
Is there a possibility to store large numbers?
Thank you
char str[1024];
in place ofchar *str= (char*)malloc(sizeof(char)*1024);
. Fewer memory management headaches in the future. – Billfish