Announcement

Collapse
No announcement yet.

String Matching / Saving

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

  • String Matching / Saving

    Hello,

    I have a question on how str_Match() functions, and likely this will dip into my (lack of) understanding of string pointers in general. My goal is to receive input from serial, and then if the input is different than what I currently have printed on the display, I would like to re-print. I would expect that this should be fairly simple. Here's a code snippet:

    Setup:

    Code:
    to(displayUnits0); putstr("");

    Iterations (each time I receive a serial command):

    Code:
    newUnitsStringPtr := str_Ptr(newUnitsString);
    prevPtr := str_Ptr(displayUnits0);
    
    // Some debug printing statements:
        print("OLD STRING: ", [STR]displayUnits0,"\n");
        print("NEW STRING: ", [STR]newUnitsString, "\n");
        print("Match RESULT: ",str_Match(&prevPtr,newUnitsStringPtr));
        pause(500);
    
    // The actual switcher-oo:
    if(str_Match(&prevPtr,newUnitsStringPtr) == 0)
            str_Copy(prevPtr,newUnitsStringPtr);
           // then do some printing stuff
    So here's the behavior that I'm observing. Up on the first iteration, the array displayUnits0 is set to blank "", and when I first send a serial command the comparison works like I expect, and the copy saves the new string within newUnitsString to displayUnits0. After that I see the debug printing those two strings out the same. Now, when I send a serial command that has a different string, the debug printing shows that it is different (for example, I see on the display:

    OLD STRING: mm
    NEW STRING: in

    but...

    Match RESULT: 414

    I would expect that the match result should be 0, like it should when it doesn't find a match. And then it should enter my if statement and update it again. I must be missing something basic because it certainly updates the very first time I run through it -> just every other time it doesn't behave like I would expect with the str_Match() function. Any help would be appreciated.

Working...
X