Results 1 to 4 of 4

Thread: Passing an Array as a paramater

  1. #1
    Join Date
    May 2012
    Location
    Draynor Willows
    Posts
    498
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default Passing an Array as a paramater

    I'm passing an array as a argument into a procedure. I'm stuck with an error.

    Code:
    statsCreation(stats[ASIZE]);
    argument of type "int" is incompatible with parameter of type "int*"

    I haven't used pointers anywhere. Anyone know what the problem is? =/


    OR you could maybe help with me the problem itself, I need to check to make sure the sum of an array is within two integers.

  2. #2
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    paste the whole code that is relevant to that line. for addition of the array just loop through the array and add them one by one?

    for (int i=0;i<len;++i) total +=arr[i];

    if (total >= lownum && total <= highnum) dosomething;

  3. #3
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Arrays in C are automatically declared as pointers. So if stats is an array, that line needs to be
    Code:
    statsCreation(stats)


  4. #4
    Join Date
    Dec 2011
    Location
    -bash
    Posts
    515
    Mentioned
    0 Post(s)
    Quoted
    27 Post(s)

    Default

    You need to use a dynamically allocated array. Or pass a pointer to the array to the function

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •