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 / ITOD.C < prev    next >
Text File  |  2000-06-30  |  768b  |  31 lines

  1.  
  2. #include stdio.h
  3. /*
  4. ** itod -- convert nbr to signed decimal string of width
  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. itod(nbr, str, sz) int nbr; char str[]; int sz; {
  12.   char sgn;
  13.   if(nbr<0) {nbr = -nbr; sgn='-';}
  14.   else sgn=' ';
  15.   if(sz>0) str[--sz]=NULL;
  16.   else if(sz<0) sz = -sz;
  17.   else while(str[sz]!=NULL) ++sz;
  18.   while(sz) {
  19.     str[--sz]=(nbr%10+'0');
  20.     if((nbr=nbr/10)==0) break;
  21.     }
  22.   if(sz) str[--sz]=sgn;
  23.   while(sz>0) str[--sz]=' ';
  24.   return str;
  25.   }
  26.  
  27.  
  28. e feof() and ferror() to determine file status.
  29. */
  30. read(fd, buf, n) int fd, n; char *buf; {
  31.   char *cnt; /*fake unsigned*