Thread: Testing some code, lots of errors...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    98
    Quote Originally Posted by laserlight View Post
    Both stevesmithx and I asked you to post your current (i.e., most recent) code, not the code that you started out with.
    Code:
    double pop (double stack[], int *stackSize);
    void push (double stack[], int *stackSize, double x);
    
    int main (void)
    {
    	double stack[4]={1.0, 2.0, 3.0};
    	int *stackSize;
    	int stackSz=0;
    	stackSize=&stackSz;
    	
    
    	push(stack, stackSize, 9.0);
    	printf("%lf\n", pop(stack, stackSize));
    	push(stack, stackSize, 8.0);
    	push(stack, stackSize, 7.0);
    	push(stack, stackSize, 6.0);
    	printf("%lf\n", pop(stack, stackSize));
    	printf("%lf\n", pop(stack, stackSize));
    	printf("%lf\n", pop(stack, stackSize));
    }
    
    double pop (double stack[], int *stackSize)
    {
    	double value=0;
    	value=stack[*stackSize];
    	--stackSize;
    	return value;
    }
    
    void push (double stack[], int *stackSize, double x)
    {
    	stack[*stackSize]=x;
    	++stackSize;
    }
    I got it working, unfortunately the problem I started with in the beginning is still here...

    Output is:
    9.000000
    6.000000
    6.000000
    6.000000
    Press any key to continue . . .
    If you can't tell, it's a problem with changing the value the pointer points too so I can get other values in the array.

    [edit] - So I suppose the question is can I change the value the pointer points too without using a pointer to a pointer...
    Last edited by Sparrowhawk; 12-15-2008 at 01:34 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. set testing code
    By zxcv in forum C++ Programming
    Replies: 8
    Last Post: 12-22-2008, 02:58 AM
  2. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM
  3. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  4. linked list source code errors
    By C++_Learner in forum C++ Programming
    Replies: 1
    Last Post: 04-18-2002, 11:04 PM
  5. Reqd. C source code for Testing purposes
    By DP in forum C Programming
    Replies: 5
    Last Post: 01-14-2002, 12:45 PM