可移植printf源码
/* tab space = 4 *//********************************************************************** DISCLAIMER: ** The software supplied by Renesas Technology America Inc. is ** intended and supplied for use on Renesas Technology products. ** This software is owned by Renesas Technology America, Inc. or ** Renesas Technology Corporation and is protected under applicable ** copyright laws. All rights are reserved. ** ** THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, ** IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO IMPLIED ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ** APPLY TO THIS SOFTWARE. RENESAS TECHNOLOGY AMERICA, INC. AND ** AND RENESAS TECHNOLOGY CORPORATION RESERVE THE RIGHT, WITHOUT ** NOTICE, TO MAKE CHANGES TO THIS SOFTWARE. NEITHER RENESAS ** TECHNOLOGY AMERICA, INC. NOR RENESAS TECHNOLOGY CORPORATION SHALL, ** IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR ** CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER ARISING OUT OF THE ** USE OR APPLICATION OF THIS SOFTWARE. **********************************************************************//*-----------------------------------------------------------------------------FILE NAME: 易做图_printf.c-----------DESCRIPTION: Simplified printf and sprintf. (float and signed values no supported)-----------DETAILS:------------------Revision History------------------1.6 April 7, 2007Changed "..." access over to using standard "va_" macros for compatibility with other compilers.1.5 July 16, 2006Initialized local "s" in _print_out() in order to suppress compiler warning.1.4 April 28, 2006ROM/RAM reductions. Also NC30WA V.5.40 compatable.1.3 Feb 21, 2006Combined printf and sprintf functions1.2 Nov 15, 2005Fixed bug when using "%lx" or %lX1.1 Sept 8, 2005Fixed bug when using "%Ld"Fixed bug for sprintf (did not add NULL at end)1.0 ??, 2005Initial Version-----------------------------------------------------------------------------*/#include <stdio.h>#include <stdarg.h>#if defined NC308#define FAR _far#elif defined NC30#define FAR _far#else#define FAR#endifenum { UI, UH, UL, SI, SH, SL };enum { LEFT_SPACE, PREFIX, ZERO_PAD, VALUE_TXT, RIGHT_SPACE, OUT_DONE};static const struct{char c[2];char size;} prefix[]={{{0,0},0}, /* 0: default, no prefix */{{'-',0},1}, /* 1: minus sign */{{'+',0},1}, /* 2: plus sign */{{' ',0},1}, /* 3: space */{{'0','x'},2}, /* 4: hex 0x */{{'0','X'},2}, /* 5: hex 0X */};/* Function Prototypes */int _print_out(char FAR *s, const char FAR *format, va_list sp);int sprintf(char FAR *s, const char FAR *format, ...){int return_count;va_list sp;va_start(sp, format);return_count = _print_out(s, format, sp);va_end(sp);return (return_count);}int printf(const char FAR *format, ...){int return_count;va_list sp;va_start(sp, format);return_count = _print_out(NULL, format, sp);va_end(sp);return (return_count);}int _print_out(char FAR *s, const char FAR *format, va_list sp){int total = 0;char tmp_buf[12]; /* maximum tmp_buf usage is 12 in %d *//* Loop through format string */while ( *format ) /* loop till hit NULL */{unsigned char tmp_char, index, out_state;unsigned char left_justify = 0; /* set default to right justify */unsigned char prefix_select = 0; /* set default prefix to none */int min_width = 0; /* set default field min_width to 0 */int precision = 0; /* set default precision to 0 */unsigned char size_type = UI; /* set default type to unsigned int */char const FAR * str_ptr = tmp_buf; /* set default string source to buffer */union{unsigned long UL;signed long SL;&n补充:软件开发 , C++ ,
上一个:HDU4707:Pet(DFS)
下一个:冒泡排序
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊