Announcement

Collapse
No announcement yet.

PB Equivevalent to some basic C/C++ Code? (Pointer to an array of chars)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB Equivevalent to some basic C/C++ Code? (Pointer to an array of chars)

    Hi I'm new here. Just out of curiosity I'd like to know how the below could be converted to PB7
    Code:
    C/C++ Code
    #include <stdio.h>
    
    int main()
    {
    	char a[] = "hello";
    	char * b;
    
    	b = a;
    
    	printf(b);
    
    	return 0;
    }
    What is the "equivevalent" in PB to the code above?

    I came up with something like this but it won't compile
    Code:
    #COMPILE EXE
    
    #INCLUDE "WIN32API.INC"
    
    FUNCTION PBMAIN()
        LOCAL a AS ASCIIZ * 6
        LOCAL b AS ASCIIZ POINTER
        
        a = "Hello"
        b = a
        MSGBOX b
    END FUNCTION
    Which keyword should I use here to point b to a and print the text on screen via b?
    I tried using b = VARPTR(a) but that doesn't go well with MSGBOX()

    ------------------

  • #2
    Take look in PB help - Data types - Pointer data types. To get the
    value of a pointer variable, place an @ before it, like:
    Code:
        a = "Hello"
        b = VARPTR(a)   ' or STRPTR() if a is STRING
        PRINT @b

    ------------------
    http://www.tolkenxp.com/pb
    Download: incLean, PBcodec, custom controls and code, etc.
    Borje Hagsten - [email protected]

    Comment


    • #3
      Thanks a bunch

      ------------------

      Comment


      • #4
        I think you had the answer yourself all along.. it's in the title of your post..

        "pointer to array of characters"
        Code:
        Array       = end-to-end collection of like-size items accessed by an index or subscript
        Character   = Byte
          REDIM Z (enough) AS BYTE
        Pointer     = addresss
        Address     = VARPTR
          Pointer to array = VARPTR(Z(0))

        MCM


        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X