Thread: can any one explain me the error.?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    82

    can any one explain me the error.?

    Hey all! i m new to dynamic arrays and pointers... can any one explain me the error??
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    //-- inputarray defi --
    void inputarray(int size, double* array){
         array=(double *)malloc(size*sizeof(double));
         
         int a=0;
         for(; a<size; a++){
               scanf("%lf",(array+a));
                            }     
    }
    // ** inputarray end **
    
    
    //-- printarray defi --
    void printarray(int size, double* array){
         array=(double *)malloc(size*sizeof(double));
         
         int a=0;
         for(; a<size; a++){
               print("%lf",(array+a));
                            }     
    }
    // ** printarray end **
    
    //-- main --
    int main()
    {
        int* arr1, arr2;
        int size1,size2;
        
        printf("Enter the size of aray 1: ");
        scanf("%d",&size1);
        inputarray(*arr1,size1);
        
        printarray(*arr1,size);
        
        
        return 0;
    }
    //** main end **
    Error:
    36 C:\Users\Administrator\Desktop\ass 6\2.c [Warning] passing arg 2 of `inputarray' makes pointer from integer without a cast

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Are you really sure you want to reallocate memory for array just before printing it? Delete line 19 and see what happens.

    lines 11 and 23 would be more explicit (readable) if you used standard array notation... array[a]...

    lines 9-10 and 21-22 are screwball ways to initialize a for loop that do little more than reduce the readbility of your code. Use the standard format.... for (a = 0; a < size; a++) ...

    lines 36 and line 38 ... lose the asterisks.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    In C the order of parameters passed to a function must be correct.

    Tim S.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by stahta01 View Post
    In C the order of parameters passed to a function must be correct.

    Tim S.
    Nice catch, Tim... I completely missed that.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    thnx alll....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someone explain why the double quotes give me error here?
    By byebyebyezzz in forum C++ Programming
    Replies: 5
    Last Post: 10-27-2011, 12:51 PM
  2. Can someone please explain this error?
    By cprogrammer1980 in forum C Programming
    Replies: 9
    Last Post: 03-26-2011, 01:46 PM
  3. Can Anyone Explain this Error? (OpenGL)
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 11-29-2005, 06:21 PM
  4. Program Fatal Error- Please Explain
    By luckygold6 in forum C++ Programming
    Replies: 9
    Last Post: 03-06-2003, 08:56 PM
  5. Can someone explain this error?
    By brianhj in forum Windows Programming
    Replies: 5
    Last Post: 10-17-2001, 02:34 PM