home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / SMC21LIB.LZH / ITOU.C < prev    next >
Text File  |  2000-06-30  |  768b  |  31 lines

  1.  
  2. #include stdio.h
  3. /*
  4. ** itou -- convert nbr to unsigned decimal 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. itou(nbr, str, sz) int nbr; char str[]; int sz; {
  12.   int lowbit;
  13.   if(sz>0) str[--sz]=NULL;
  14.   else if(sz<0) sz = -sz;
  15.   else while(str[sz]!=NULL) ++sz;
  16.   while(sz) {
  17.     lowbit=nbr&1;
  18.     nbr=(nbr>>1)&32767; /*divide by 2*/
  19.     str[--sz]=((nbr%5<<1)+lowbit+'0');
  20.     if((nbr=nbr/5)==0) break;
  21.     }
  22.   while(sz) str[--sz]=' ';
  23.   return str;
  24.   }
  25.  
  26.  
  27. 029,
  28.     030,031,032,033,034,035,036,037,038,039,
  29.     040,041,042,043,044,045,046,047,
  30.     /**** 0 to 9 ****/
  31.     065,066,