Note that there are some explanatory texts on larger screens.

plurals
  1. POcalling function with pointers and arrays properly
    primarykey
    data
    text
    <p>I'm really puzzled as to how to call the function. UPDATED code in response to one or more answers. Current code and build errors are listed below. </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; //function prototypes void signs(int x[], int size, int *negPtr, int *zeroPtr, int *posPtr); double average(int x[], int size, int *greaterPtr); int main() { //variable declarations int zeroCounter, posCounter, negCounter, greaterThanAveCounter; double ave; int i; int arr[63]; int size = 63; int x[63], int size, int* negPtr, int* zeroPtr, int* posPtr, int* greaterPtr; //seeding the random number generator function with the time srand(time(NULL)); //filling the array with random numbers from the interval [-15, 40] for(i=0; i&lt;63; i++) { arr[i] = rand()%(40-(-15)+1)+(-15); } //printing the array to the screen 9 elements per line for(i=0; i&lt;63; i++) { if(i%9==0) { printf("\n"); } printf("%5d",arr[i]); } //call function signs signs (x, size, negPtr, zeroPtr, posPtr); printf("\n\nThe number of elements that are negative is: %d\n",negCounter); printf("The number of elements that are equal to zero is: %d\n",zeroCounter); printf("The number of elements that are positive is: %d\n",posCounter); //call function average average(x, size, greaterPtr); printf("The average of all the elements is: %.2f\n",ave); printf("The number of elements that are greater than the average is: %d\n",greaterThanAveCounter); return 0; } /*************************************************************************** signs: This function finds the number of elements that are negative, positive and equal to zero in an integer array. The number of elements that are negative, positive and equal to zero are returned by 3 pointers that the function receives. Inputs 1. The integer array 2. The size of the aray 3. An integer pointer to the negative counter 4. An integer pointer to the zero counter 5. An integer pointer to the positive counter ***************************************************************************/ void signs(int x[], int size, int *negPtr, int *zeroPtr, int *posPtr) { int i; for (i=0; i&lt;size; i++) { if(x[i]&lt;0) { (*negPtr)++; } else if (x[i]==0) { (*zeroPtr)++; } else { (*posPtr)++; } } } /*************************************************************************** average: This function finds the average and the number of elements that are greater than the average in an integer array. The function returns the value of the average and returns the number of elements that are greater than the average using a pointer that the function should receive. Inputs 1. The integer array 2. The size of the aray 3. An integer pointer to the greater than average counter ***************************************************************************/ double average(int x[], int size, int *greaterPtr) { int i; double ave; int sum=0; for (i=0; i&lt;size; i++) { sum+=x[i]; } ave = (double)sum/size; *greaterPtr = 0; for (i=0; i&lt;size; i++) { if(x[i]&gt;ave) { (*greaterPtr)++; } } return ave; } </code></pre> <p>New Errors</p> <ul> <li>(32): error C2059: syntax error : 'type' </li> <li>(35): warning C4244: 'function' : conversion from 'time_t' to 'unsigned int', possible loss of data </li> <li><p>(54): error C2065: 'negPtr' : undeclared identifier</p></li> <li><p>(54): warning C4047: 'function' : 'int *' differs in levels of<br> indirection from 'int'</p></li> <li>(54): warning C4024: 'signs' : different types for formal and actual parameter 3</li> <li>(54): error C2065: 'zeroPtr' : undeclared identifier</li> <li><p>(54): warning C4047: 'function' : 'int *' differs in levels of indirection from 'int'</p></li> <li><p>(54): warning C4024: 'signs' : different types for formal and actual parameter 4</p></li> <li>(54): error C2065: 'posPtr' : undeclared identifier</li> <li><p>(54): warning C4047: 'function' : 'int *' differs in levels of indirection from 'int'</p></li> <li><p>(54): warning C4024: 'signs' : different types for formal and actual parameter 5</p></li> <li><p>(62): error C2065: 'greaterPtr' : undeclared identifier</p></li> <li><p>(62): warning C4047: 'function' : 'int *' differs in levels of<br> indirection from 'int'</p></li> <li>(62): warning C4024: 'average' : different types for formal and actual parameter 3</li> <li>1> 1>Build FAILED.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload