韦东山裸机代码

源代码在线查看: printf.c

软件大小: 156 K
上传用户: newyearday
关键词: 代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				#include "vsprintf.h"				#include "string.h"				#include "printf.h"								extern void putc(unsigned char c);				extern unsigned char getc(void);								#define	OUTBUFSIZE	1024				#define	INBUFSIZE	1024				
				
				static unsigned char g_pcOutBuf[OUTBUFSIZE];
				static unsigned char g_pcInBuf[INBUFSIZE];
				
				
				int printf(const char *fmt, ...)
				{
					int i;
					int len;
					va_list args;
				
					va_start(args, fmt);
					len = vsprintf(g_pcOutBuf,fmt,args);
					va_end(args);
					for (i = 0; i < strlen(g_pcOutBuf); i++)
					{
						putc(g_pcOutBuf[i]);
					}
					return len;
				}
				
				
				
				int scanf(const char * fmt, ...)
				{
					int i = 0;
					unsigned char c;
					va_list args;
					
					while(1)
					{
						c = getc();
						if((c == 0x0d) || (c == 0x0a))
						{
							g_pcInBuf[i] = '\0';
							break;
						}
						else
						{
							g_pcInBuf[i++] = c;
						}
					}
					
					va_start(args,fmt);
					i = vsscanf(g_pcInBuf,fmt,args);
					va_end(args);
				
					return i;
				}
				
							

相关资源