Search code examples
cdynamic-arrayscomplex-numbers

2D Dynamic Array, filled with Complex numbers


I am trying to initialize a 2D Dynamic array with complex doubles in it. I can't figure out what this error message is telling me to do and can't find it anywhere.

#include <complex.h> 
...
int main( int argc, char *argv[] ) {
    complex double **A;
    FILE *inputFile;
    int i;
    double numRow, numCol;

    inputFile = fopen( "input.txt", "r" );
    fscanf( inputFile, "%lf %lf", &numRow, &numCol );

    A = ((complex double)**)malloc( numRow * sizeof( (complex double)* ) );
    for( i = 0; i < numCol ; i++ ) {
        A[i] = ((complex double)*)malloc( NC * sizeof( (complex double) ) );


    for( i = 0; i < m; ++i ) {
        free( A[i] );
    }
    free( A );

The error I'm getting comes from the two lines which call malloc.

gewhpp.c:58:26: error: expected expression before â)â token
gewhpp.c:60:29: error: expected expression before â)â token

Solution

  • Try editing the lines with complex double to look like this:

    A = (complex double**)malloc( numRow * sizeof(complex double* ));
    

    You don't need to bracket around 'complex double' and then put the '*'

    (You have some other errors with your braces, but I suppose that is because this is just snippets of code...)