diff options
author | Freya Murphy <freya@freyacat.org> | 2025-03-25 17:36:52 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-03-25 17:38:22 -0400 |
commit | 6af21e6a4f2251e71353562d5df7f376fdffc270 (patch) | |
tree | de20c7afc9878422c81e34f30c6b010075e9e69a /lib/cvtdec0.c | |
download | comus-6af21e6a4f2251e71353562d5df7f376fdffc270.tar.gz comus-6af21e6a4f2251e71353562d5df7f376fdffc270.tar.bz2 comus-6af21e6a4f2251e71353562d5df7f376fdffc270.zip |
initial checkout from wrc
Diffstat (limited to 'lib/cvtdec0.c')
-rw-r--r-- | lib/cvtdec0.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/cvtdec0.c b/lib/cvtdec0.c new file mode 100644 index 0000000..87792e0 --- /dev/null +++ b/lib/cvtdec0.c @@ -0,0 +1,44 @@ +/** +** @file cvtdec0.c +** +** @author Numerous CSCI-452 classes +** +** @brief C implementations of common library functions +*/ + +#ifndef CVTDEC0_SRC_INC +#define CVTDEC0_SRC_INC + +#include <common.h> + +#include <lib.h> + +/** +** cvtdec0(buf,value) - local support routine for cvtdec() +** +** convert a 32-bit unsigned integer into a NUL-terminated character string +** +** @param buf Destination buffer +** @param value Value to convert +** +** @return The number of characters placed into the buffer +** (not including the NUL) +** +** NOTE: assumes buf is large enough to hold the resulting string +*/ +char *cvtdec0( char *buf, int value ) { + int quotient; + + quotient = value / 10; + if( quotient < 0 ) { + quotient = 214748364; + value = 8; + } + if( quotient != 0 ) { + buf = cvtdec0( buf, quotient ); + } + *buf++ = value % 10 + '0'; + return buf; +} + +#endif |