I'm using Dev-C++

Im making my arrays dynamically and I am calling on a function to allocate the memory for me, but I received the warning:

"[Warning] assignment makes pointer from integer without a cast "
This occurs in main when alocate is called

Main funtion:

int main()
    int exit,temp,SIZE,i,j,fromA,toB, tryagain=1, counter;
    char filename[50];
    FILE *infile;
    int **matrix; /*point to array of pointers*/
    int **tmpmat; /*Holds values for matrix raised to a power*/
    int **C;
    printf("Enter File Name: ");
    infile = fopen(filename, "r+");   /*opens data file*/
    if(infile == NULL) /*check to see if file opened properly*/
         printf("Cannot open the input file- Enter 1 to exit: ");
    fscanf(infile, "%d", &SIZE);/*reads size of adj matrix*/
    printf("The adjacency matrix size is %dx%d\n\n", SIZE, SIZE);
/*******Making Array dynamically**************/
    matrix = alocate(SIZE);
    tmpmat = alocate(SIZE);
    C = alocate(SIZE);
/************End of dyanamic array making********/

Here's the funtions it calls
I get the Warning: return makes integer from pointer without a cast

int alocate(int SIZE)
    int i;
    int **new;
    new = malloc(SIZE * sizeof(int *));
    if (new == NULL) {
         printf("Error: malloc could not allocate %d bytes for a\n", (SIZE * sizeof(int *)));
         return -1;
    for (i=0; i<SIZE; i++) 
         new[i] = malloc(SIZE * sizeof(int));    
    return new;
7 Years
Discussion Span
Last Post by Zach101man

you're trying to return an int ** , and your assignments expect the same.

but your function return type is int


Thanks that works, I knew it had to be something simple. I'm still trying to get used to these pointers

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.