设为首页 加入收藏

TOP

C语言学习趣事_MSCRT_IO_SourceFile (十)
2014-11-24 00:40:18 来源: 作者: 【 】 浏览:260
Tags:语言学习 趣事 _MSCRT_IO_SourceFile
NSI. */
if (precision < 0)
precision = 1; /* default precision */
else
flags &= ~FL_LEADZERO;

/* 4. Check if data is 0; if so, turn off hex prefix */
if (number == 0)
prefixlen = 0;

/* 5. Convert data to ASCII -- note if precision is zero */
/* and number is zero, we get no digits at all. */

text.sz = &buffer.sz[BUFFERSIZE-1]; /* last digit at end of buffer */

while (precision-- > 0 || number != 0) {
digit = (int)(number % radix) + '0';
number /= radix; /* reduce number */
if (digit > '9') {
/* a hex digit, make it a letter */
digit += hexadd;
}
*text.sz-- = (char)digit; /* store the digit */
}

textlen = (char *)&buffer.sz[BUFFERSIZE-1] - text.sz; /* compute length of number */
++text.sz; /* text points to first digit now */


/* 6. Force a leading zero if FORCEOCTAL flag set */
if ((flags & FL_FORCEOCTAL) && (text.sz[0] != '0' || textlen == 0)) {
*--text.sz = '0';
++textlen; /* add a zero */
}
}
break;
}

/* At this point, we have done the specific conversion, and */
/* 'text' points to text to print; 'textlen' is length. Now we */
/* justify it, put on prefixes, leading zeros, and then */
/* print it. */

if (!no_output) {
int padding; /* amount of padding, negative means zero */

if (flags & FL_SIGNED) {
if (flags & FL_NEGATIVE) {
/* prefix is a '-' */
prefix[0] = _T('-');
prefixlen = 1;
}
else if (flags & FL_SIGN) {
/* prefix is '+' */
prefix[0] = _T('+');
prefixlen = 1;
}
else if (flags & FL_SIGNSP) {
/* prefix is ' ' */
prefix[0] = _T(' ');
prefixlen = 1;
}
}

/* calculate amount of padding -- might be negative, */
/* but this will just mean zero */
padding = fldwidth - textlen - prefixlen;

/* put out the padding, prefix, and text, in the correct order */

if (!(flags & (FL_LEFT | FL_LEADZERO))) {
/* pad on left with blanks */
WRITE_MULTI_CHAR(_T(' '), padding, &charsout);
}

/* write prefix */
WRITE_STRING(prefix, prefixlen, &charsout);

if ((flags & FL_LEADZERO) && !(flags & FL_LEFT)) {
/* write leading zeros */
WRITE_MULTI_CHAR(_T('0'), padding, &charsout);
}

/* write text */
#ifndef WPRFLAG
if (bufferiswide && (textlen > 0))
{
wchar_t *p;
int retval, count;
char buffer[MB_LEN_MAX+1];

p = text.wz;
count = textlen;
while (count--) {
retval = wctomb(buffer, *p++);
if (retval <= 0)
break;
WRITE_STRING(buffer, retval, &charsout);
}
}
else
{
WRITE_STRING(text.sz, textlen, &charsout);
}
#else
if (!bufferiswide && textlen > 0) {
char *p;
int retval, count;

p = text.sz;
count = textlen;
首页 上一页 7 8 9 10 11 12 下一页 尾页 10/12/12
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇STL 应用之set 下一篇快速计算32位数中1的位数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: