SOLVED - Pointer passing

Hi all, I'm having a problem with passing pointers to an array of long integers to a function which should change the contents of that array.

Code:
1
2
3
4
5
long values243[9];

// stuff

writePBrkStat(ptrBrkStFile, values243);


The last line calls this function:

1
2
3
4
5
6
7
8
9
void writePBrkStat(FILE *filePtr, long *counter)
{
     if(*counter != 0)
     {
          fprintf(filePtr, "1\n");  //don't ask, please >_>
          *counter--;
     }
     else fprintf(filePtr, "0\n");
}


Now, the first element of values243[] is correctly initialized with 3 before the function call, so that the function should be executed 3 times, until the counter hits zero and the function prints zero to the file (the file is going to be used for a rectangle pulse curve).

Can someone tell me what I'm doing wrong? Because I (as ever so often) can't seem to find it.
Last edited on
*counter-- is the same as counter--. You're not changing the value of *counter. You're changing the value of counter. Replace with (*counter)--.
Oddly enough, with the change you suggested, it still changes the pointer, and not the value it points to TT_TT
And interestingly, the if-statement never gets executed (I traced it), yet the pointer experiences change (although I'm not doing anything to change it, outside of the if statement).

Edit: PBKAC.
Last edited on
Topic archived. No new replies allowed.