home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / VideoToolboxSources / BreakLines.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-13  |  1.1 KB  |  42 lines  |  [TEXT/KAHL]

  1. /*
  2. BreakLines.c
  3.  
  4. char *BreakLines(char *string,long lineLength);
  5.  
  6. Takes a long C string and judiciously changes spaces to '\n' to yield lines
  7. shorter than lineLength, but words are never broken, even if they are longer
  8. than lineLength. All characters other than space and '\n' are treated as letters.
  9.  
  10. The default THINK C console width is 80, so use printf(BreakLines(string,80));
  11. */
  12. #include "VideoToolbox.h"
  13. char *BreakLines(char *string,long lineLength);
  14.  
  15. char *BreakLines(char *string,long lineLength)
  16. {
  17.     long i,leftMargin,rightMargin,length;
  18.     Boolean here;
  19.     
  20.     leftMargin=0;
  21.     length=strlen(string);
  22.     while(1){
  23.         rightMargin=leftMargin+lineLength;
  24.         if(rightMargin>=length)return string;        // successful completion
  25.         here=0;
  26.         if(!here)for(i=leftMargin;i<rightMargin;i++)if(string[i]=='\n'){
  27.             here=1;
  28.             break;
  29.         }
  30.         if(!here)for(;i>=leftMargin;i--)if(string[i]==' ' || string[i]=='\n'){
  31.             here=1;
  32.             break;
  33.         }
  34.         if(!here)for(i=leftMargin;i<length;i++)if(string[i]==' ' || string[i]=='\n'){
  35.             here=1;
  36.             break;
  37.         }
  38.         if(!here)return string;
  39.         string[i]='\n';
  40.         leftMargin=i+1;
  41.     }
  42. }