Thread: Arrays and Pointers

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    7

    Arrays and Pointers

    I keep getting two errors and I don't know how to fix it. I am still getting my executable on the Unix server...I'm just confused.
    Line21 passing argument 2 of 'array_processing' makes integer from pointer without a cast [enabled by default]

    Line2 note: expected 'int' but argument is of type 'int *'



    This is my code:
    Code:
    #include<stdio.h>
    void array_processing (int x[],int size,int *min,int *max,float *mean)
    {
    int i,sum=0;
    for(i=0;x[i]!=0;i++)
    {
    size = 23;
    if(*min>x[i])
    *min=x[i];
    if(*max<x[i])
    *max=x[i];
    sum+=x[i];
    }
    *mean=sum*1.0/size;
    }
    int main(void)
    {
    int data_ar[23]={3,5,6,7,12,3,4,6,19,23,100,3,4,2,9,43,32,45,32,2,3,2,1};
    int MIN[2]={210000},MAX[2]={0},SIZE[2]={0};
    float MEAN[2]={0};
    array_processing(data_ar,SIZE,MIN,MAX,MEAN);
    printf("The min of the array is: %d\n", MIN[0]);
    printf("The max of the array is: %d\n", MAX[0]);
    printf("The mean of the array is: %f\n", MEAN[0]);
    return (0);
    }

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    In line 2 you probably want "int *size". You forgot the asterisk.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    7
    My instructions for this problem has it without an * so all I did was copy and past the void array processing...

    Write a program that returns the min, max and mean value of an array of integers named data_ar. Your
    program should call a single function that returns that mean, max and mean value of the array. The declaration of this function
    is given below:
    Code:
    void array processing(int x[ ], int size, int *min, int *max, float *mean) 
    {
    body of function 
    } 
    Declare the array of integers within the main function 
    int data_ar[ ] = {3, 5, 6, 7, 12, 3, 4, 6, 19, 23, 100, 3, 4, 2, 9, 43, 32, 45, 32, 2, 3, 2, 1};
    Last edited by Frasiany; 04-01-2013 at 06:06 PM.

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    7
    Also, if I do add the * there is an error with line 7 and 14...

  5. #5
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Why does SIZE need to be an array in the first place?
    Code:
    while(!asleep) {
       sheep++;
    }

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    7
    To calculate the mean. My professor wants it that way.. And that is why I am confused lol.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is your current code? Also, you should indent your code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Apr 2013
    Posts
    7
    My code is still the same from the original cause having a pointer on size just created more problems...

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    > void array_processing (int x[],int size,int *min,int *max,float *mean)
    How do you use size within the body of the function?

    > size = 23;
    What is this supposed to do?

    > for(i=0;x[i]!=0;i++)
    This kind of loop only really works for \0 terminated character strings.
    Is there a zero at the end of your array in main? It doesn't look like it.

    Have you considered say
    for(i=0;x<size;i++)

    > array_processing(data_ar,SIZE,MIN,MAX,MEAN);
    If you've got this far, and understood that the parameter size is a count of the number of elements in the array, can you fix this?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Apr 2013
    Posts
    7
    Well I am a beginner with C and we just started learning about arrays. The 23 means the number of numbers in data_ar so I will be able to calculate the mean.Size isn't really a pointer I guess I don't really know its what my professor provided me..

  11. #11
    Registered User
    Join Date
    Apr 2013
    Posts
    7
    I ended up figuring out this code by myself. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers to pointers with arrays
    By Nurumla in forum C Programming
    Replies: 3
    Last Post: 07-18-2011, 11:53 PM
  2. Replies: 7
    Last Post: 05-19-2010, 02:12 AM
  3. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 05:31 AM
  4. pointers to 2d arrays
    By Diamonds in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2002, 06:58 AM
  5. arrays and pointers
    By rippascal in forum C++ Programming
    Replies: 5
    Last Post: 03-21-2002, 11:01 AM