Announcement

Collapse
No announcement yet.

delete last value of buffer

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

  • delete last value of buffer

    Hello,

    how can i delete the last char of a buffer ?

    best regards,
    alex

  • #2
    Hi Alex,

    You can delete the last character of your buffer by setting your last element as a NULL value.

    For example, if your last element is in the 5th position, then:

    Code:
    array[4]:=0;
    You may use this another example as well :

    Code:
        var buffer[30];   // buffer array
        var ptr;          // byte aligned pointer to buffer
            ptr:=str_Ptr(buffer);
        var ctr := 0;     // number of characters stored
        var chr;
    
        for (chr := 'a'; chr < 'z'; chr++)
            // Assumming characters are stored using the line of code below:
            str_PutByte(ptr + (ctr++), chr); // chr is the new character to store
        next
    
        // The last character can be removed using:
        str_PutByte(ptr + (ctr--), 0);
    
        print([STR] buffer);
    Hope this helps and Best Regards
    Eran

    Comment


    • #3
      Thanks for your reply!
      the second code example works good for me.

      i'am trying to implement a 'backspace' function for my keyboard. it needs to delete the last value in the buffer..
      when i use your way, i can delete the last char, but i can't get the first one deleted
      ___________________________
      For example:


      buffer['s','f','e'];
      backspace();
      print([STR]buffer) --> sf

      backspace();
      print([STR]buffer) --> s

      backspace();
      print([STR]buffer) --> s
      ____________________________

      any ideas why ?

      Comment


      • #4
        Hello Alex,

        To replace the first element in the array, make sure the pointer in the str_PutByte points to the first address.
        In the case of the code str_PutByte(ptr + (ctr), 0); ctr should be equal to 0 to point to the first element.

        Best Regards,

        Comment

        Working...
        X