Advertisement
Guest User

String buffer management corrected

a guest
Sep 17th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. void    buff_management(char *str, char mode)
  2. {
  3.     static char buff[BUFF_SIZE];
  4.     static char *buff_ptr = buff;
  5.    
  6.     if (!mode)
  7.     {
  8.         while (*str)
  9.         {
  10.             if (buff_ptr - buff >= BUFF_SIZE - 1)
  11.             {
  12.                 write(1, buff, strlen(buff));
  13.                 buff_ptr = buff;
  14.                 memset(buff_ptr, 0, BUFF_SIZE);
  15.             }
  16.             *buff_ptr = *str;
  17.             str++;
  18.             buff_ptr++;
  19.         }
  20.     }
  21.     else
  22.     {
  23.         write(1, buff, strlen(buff));
  24.         buff_ptr = buff;
  25.         memset(buff_ptr, 0, BUFF_SIZE);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement