Announcement

Collapse
No announcement yet.

String pointer problem

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

  • String pointer problem

    Hi, thanks to everyone involved into this new Workshop 4, looks much better.

    Unfortunately I'm having some problems with strings.

    Maybe I'm doing something wrong, well here is my code:

    Code:
    #platform "uLCD-32PT"
    
    #constant BUFSIZE 10 // Max 20 chars
    var testBuf2[BUFSIZE];
    var testBuf[BUFSIZE];
    var testPtr;
    
    
    func main()
    
        var ch;
    
        setbaud(BAUD_9600);
    
        gfx_Cls();
        txt_Set(FONT_SIZE, FONT2);
        print ("Test\n");
    
        testPtr := str_Ptr(testBuf);
        print("testPtr=0x",[HEX4]testPtr,"\n");
        print("testPtr=",testPtr,"\n");
    
        to(testBuf); print("123456");
        print("[",[STR]testPtr,"]\n");
    
        /* 
        print("\nString contains 0? Pos=",[HEX4] str_Find(&testPtr,"0"),"\n");
        print("\nString contains 1? Pos=",[HEX4] str_Find(&testPtr,"1"),"\n");
        print("\nString contains 2? Pos=",[HEX4] str_Find(&testPtr,"2"),"\n");
        print("\nString contains 3? Pos=",[HEX4] str_Find(&testPtr,"3"),"\n");
        print("\nString contains 4? Pos=",[HEX4] str_Find(&testPtr,"4"),"\n");
        print("\nString contains 5? Pos=",[HEX4] str_Find(&testPtr,"5"),"\n");
        print("\nString contains 6? Pos=",[HEX4] str_Find(&testPtr,"6"),"\n");
        print("\nString contains 7? Pos=",[HEX4] str_Find(&testPtr,"7"),"\n");
        */
    repeat forever
    
    endfunc
    My screen shows:
    Test
    testPtr=0x0016
    testPtr=22
    []

    As you see the print function with a pointer shows nothing, I'm doing something wrong or the problem is with the function or the pointer.

    The commented code shows the result of the search perfectly so I think that the problem could be the function or something that I'm missing in my code.

    What do you think?

    --
    JM

  • #2


    Because testPtr is already a string pointer, you need to print it like this.

    str_Printf(&testPtr, "%s");

    BUT BE WARNED that statement alters testPtr, so if you need it further, use a copy of it.
    Mark

    Comment

    Working...
    X