Aslai

Untitled

Jul 28th, 2011
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. int wrap( const char* in, char* out, int bound )
  2. {
  3.     int i, j, track;
  4.     int spaced = 0, spacedj = 0;
  5.     i = j = track = 0;
  6.  
  7.     for( i = 0; in[i] != 0; i ++ )
  8.     {
  9.         out[j] = in[i];
  10.         if( in[i] == ' ' ){
  11.             spaced = i;
  12.             spacedj = j;
  13.         }
  14.         j++;
  15.         track++;
  16.         if( track > bound )
  17.         {
  18.             if( spaced != 0 ){
  19.                 out[spacedj+1] = '\n';
  20.                 i = spaced;
  21.                 j = spacedj+2;
  22.             }
  23.             else
  24.                 out[j++] = '\n';
  25.             track = 0;
  26.             spaced = 0;
  27.             spacedj = 0;
  28.         }
  29.     }
  30.     out[j] = 0;
  31.     return j;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment