Code:
char **seq_array;
seq_array = new (char *)[nseqs];
for (int i = 0; i < nseqs; ++i)
seq_array = new char[length];
The only differences is that, unlike calloc(), operator new does not guarantee initialisation to zero for basic types. To achieve that, modify the above to;
Code:
char **seq_array;
seq_array = new (char *)[nseqs];
for (int i = 0; i < nseqs; ++i)
{
seq_array = new char[length];
for (int j = 0; j < length; ++j)
seq_array[i][j] = 0;
}
Incidentally, the original versions with calloc() contains a minor error. It should be
Code:
char** seq_array;
seq_array = (char **)calloc( (nseqs) * sizeof (char *), sizeof(char *) );
for(int i=0; i < nseqs; i++)
seq_array[i] = (char *)calloc((length) * sizeof (char), sizeof(char));
In this example, it doesn't matter as the subsequent loop overwrites each element of seq_array, but remove that loop ......