calloc error

This is a discussion on calloc error within the C Programming forums, part of the General Programming Boards category; Dear people that know more C than me (ie Everyone) I am working on a simple bit of C code ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    3

    Question calloc error

    Dear people that know more C than me (ie Everyone)

    I am working on a simple bit of C code to fill a dynamic array with specific values and display them in a grid. However, I'm getting stuck at the beginning, when I try to allocate memory for the array. I have checked around for other calloc code, and I'm not sure where I'm making my mistake. When I try to compile my code, I receive an error that says: "incompatible implicit declaration of built-in function 'calloc'"

    The code I'm using is as follows:
    Code:
    #include<stdio.h>
    #include<math.h>
    
    main()  {
            int i, j;
    
            //values to hold row & col size for array & mem size needed
            int col, row, Doubles;
    
            printf("\nEnter the number of columns desired for your array \n");
            scanf("%d", &col);
    
            printf("\nEnter the number of rows desired for your array \n");
            scanf("%d", &row);
    
            Doubles = col * row;
    
            //declaring the array
           //THIS IS WHERE I'M GETTING THE ERROR
            double *ArrayPtr = (double *) calloc (Doubles,sizeof(double));
    
            //filling the array with the requested values
            for(i = 0; i < row; i++)
                    for(j = 0; j < col; j++)        {
                            *ArrayPtr = i * 100 + col;
                            ArrayPtr ++;
                    }
    Please let me know if you what I'm doing wrong in my calloc statement. Thank you in advance!

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    calloc() is declared in stdlib.h. You'll need to add the following line near the top of the file:
    #include<stdlib.h>
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    That's why I put "beginner" as one of the tags! Thanks itsme - that fixed it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock problem
    By Wolf` in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2010, 04:55 PM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21