home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / cpm / utils / s / smc21lib.lzh / ITOO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-25  |  640 b   |  30 lines

  1.  
  2. #include stdio.h
  3. /*
  4. ** itoo -- convert nbr to octal string of length sz
  5. **         right adjusted, blank filled; returns str
  6. **
  7. **        if sz > 0 terminate with null byte
  8. **        if sz = 0 find end of string
  9. **        if sz < 0 use last byte for data
  10. */
  11. itoo(nbr, str, sz) int nbr; char str[]; int sz; {
  12.   int digit;
  13.   if(sz>0) str[--sz]=0;
  14.   else if(sz<0) sz = -sz;
  15.   else while(str[sz]!=0) ++sz;
  16.   while(sz) {
  17.     digit=nbr&7; nbr=(nbr>>3)&8191;
  18.     str[--sz]=digit+48;
  19.     if(nbr==0) break;
  20.     }
  21.   while(sz) str[--sz]=' ';
  22.   return str;
  23.   }
  24.  
  25.  
  26. -sz]=sgn;
  27.   while(sz>0) str[--sz]=' ';
  28.   return str;
  29.   }
  30.  
  31.