pointer problem..

This is a discussion on pointer problem.. within the C Programming forums, part of the General Programming Boards category; Hello, all: I have a problem when I want to pass a pointer of an array to a function: I ...

  1. #1
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    Arrow pointer problem..

    Hello, all:
    I have a problem when I want to pass a pointer of an array to a function:
    I have a structure type contains an array
    [code]
    struct HeapStruct
    {
    int Capacity;
    int Size;
    ElementType *Elements;
    };
    [/coed]
    how could I passing a sub array to the function "Smallest" which can find the smallest value in the sub array. I wrote this and it is invalid..
    Code:
          num = Smallest(H->Elements[start], &pointer, start, end);
    This is the prototype of the function "Smallest":
    Code:
    int
    Smallest(int array[], int *i, int start, int end)

  2. #2
    Compiling
    Join Date
    Jun 2003
    Posts
    69
    sorry, I was careless, but why I cannot edit the thread?
    Code:
            struct HeapStruct
            {
                int Capacity;
                int Size;
                ElementType *Elements;
            };
    how could I passing a sub array to the function "Smallest" which can find the smallest value in the sub array. I wrote this and it is invalid..
    Code:
          num = Smallest(H->Elements[start], &pointer, start, end);

  3. #3
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    To pass a slice of an array, pass the address of the index:
    Code:
    num = Smallest(&H->Elements[start], &pointer, start, end);
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 08:53 PM
  2. Another pointer problem
    By mikahell in forum C++ Programming
    Replies: 21
    Last Post: 07-20-2006, 07:37 PM
  3. Pointer problem
    By mikahell in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2006, 10:21 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. pointer problem
    By DMaxJ in forum C Programming
    Replies: 4
    Last Post: 06-11-2003, 12:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21