Note that there are some explanatory texts on larger screens.

plurals
  1. POC program, pointer argument won't hold values
    text
    copied!<p>Hi guys I'm sorry to bother you with this but I'm starting to loose it here.. I have recently started programming in C again and I have run into some kind bug that just I can't figure out.. My C program is(should be) an easy one, so it needs to do the following: An undefined number of natural elements is read form the keyboard until a 0 is read. After that it has to compute the product of all elements and compute the number of 0-s on the end of that result..</p> <pre><code>int input(int* v) { int n = 0; do { n = n + 1; v = (int*) realloc(v,n*sizeof(int)); printf("Enter number %d: ",n); scanf("%d",&amp;v[n-1]); } while(v[n-1] != 0); n--; return n; } int tZeros(int* v, int eNb) { int i; int val = 1; for(i = 0; i &lt; eNb; i++) { val = val * v[i]; } i=0; while(val % 10 == 0) { i++; } return i; } int main (int argc, char** argv) { int* v = NULL; int eNb = input(&amp;(*v)); if(eNb&gt;0) { int zeros = tZeros(v, eNb); printf("The number of ending zeros in the product of the given numbers is: %d",zeros); } else { printf("No elements to do computations with!\n"); } free(v); return 0; } </code></pre> <p>The input function should return two things: The number of elements and the actual elements in the dynamic array.. But after the input function runs the values entered there are all lost.. I pass the argument into input as a pointer so it should change the values at the correct addresses right?</p> <p>All suggestions are welcome! Thnx!</p> <p>P.s. I think the problem is with my array v.. after exiting the input function it looses all values..</p>
 

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