Thread: Copy the content of buffer to temp buffer

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    1

    Post Copy the content of buffer to temp buffer

    Hi,
    I am writing embedded controller code by using c language, i am declaring two 8 bit buffers of size,

    Code:
    uint8_t buff[255];
    uint8_t  temp_buffer[30] = {0};
    uint16_t temp_ptr = 0;
    
    void Check_FE_recreate_frame(void)
    {
    uint16_t temp_ctr = 0;
    uint16_t kdx = 0;
    temp_buffer[temp_ptr] = buff[0];
    temp_ptr++;
    for (kdx = 1; kdx <= 20; kdx++)
    {
    if ((buff[kdx] == 0xFF) && (buff[kdx + 1] == 0xFE))
    {
    temp_buffer[temp_ptr] = 0xFF;
    temp_ptr++;
    temp_ctr++;
    kdx++; 
    }
    else
    {
    temp_buffer[temp_ptr] = buff[kdx];
    temp_ptr++;
    }
    }
    len = Rx_ptr - temp_ctr;
    }
    int main()
    {
    while(1){
    function call();
    }
    the function is running in while 1 loop, once the data is receiving in to buffer and copying into temp_buffer , for second time it is receiving data but not overwriting in to temp_buffer???
    Please help me to solve this?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,484
    First of all, indent your code.
    Code:
    uint8_t buff[255];
    uint8_t temp_buffer[30] = { 0 };
    
    uint16_t temp_ptr = 0;
    
    void Check_FE_recreate_frame(void)
    {
      uint16_t temp_ctr = 0;
      uint16_t kdx = 0;
      temp_buffer[temp_ptr] = buff[0];
      temp_ptr++;
      for (kdx = 1; kdx <= 20; kdx++) {
        if ((buff[kdx] == 0xFF) && (buff[kdx + 1] == 0xFE)) {
          temp_buffer[temp_ptr] = 0xFF;
          temp_ptr++;
          temp_ctr++;
          kdx++;
        } else {
          temp_buffer[temp_ptr] = buff[kdx];
          temp_ptr++;
        }
      }
      len = Rx_ptr - temp_ctr;
    }
    
    int main()
    {
      while (1) {
        function call();
      }
    }
    Second, where do you reset the value of temp_ptr ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copy any type of file to a memory buffer?
    By heatblazer in forum C Programming
    Replies: 16
    Last Post: 01-16-2015, 08:45 PM
  2. Copy struct to char buffer
    By jean.yves in forum C Programming
    Replies: 13
    Last Post: 12-15-2010, 02:00 PM
  3. Copy HWND into shared memory buffer
    By Opariti in forum Windows Programming
    Replies: 2
    Last Post: 12-26-2009, 01:08 PM
  4. Copy data from CPU Buffer to PC hard disk
    By zaid in forum C Programming
    Replies: 4
    Last Post: 10-29-2009, 10:15 AM
  5. copy int to buffer??
    By Gugge in forum C Programming
    Replies: 4
    Last Post: 03-19-2002, 12:17 PM

Tags for this Thread