Member Avatar for Zach101man

I'm using Dev-C++ 4.9.9.2

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: ");
    scanf("%s",filename);
  
    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: ");
         scanf("%d",&exit);
         return(-1);
    }
    
    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;
}

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

but your function return type is int

Member Avatar for Zach101man

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.