supp.c

来自「数字串转中文大写的小代码段」· C语言 代码 · 共 134 行

C
134
字号
#include	<stdio.h>#include	<stdlib.h>#include	<string.h>#include	"supp.h"#define		STACKSIZE	1024char	*unit1[] = {	"",	"拾",	"佰",	"仟"	};char	*unit2[] = {	"",	"万",	"亿"	};char	*digital[] = {	"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"	};typedef struct	meta {	int	value;	int	type;} META;META	stack[STACKSIZE];int	language = 0;int	sp = -1;int	setlang(int	lang){	language = lang;	return OK;}int	dump (){	int	i;	int	v,t;	for (i = sp; i>=0; i--) {		v = stack[i].value;		t = stack[i].type;		if (i==sp && (t >0 || (t ==0 && v ==0)))			continue;		switch (t) {		  case 0:			printf ("%s", digital[v]);			break;		  case 1:			printf ("%s", unit1[v]);			break;		  case 2:			printf ("%s", unit2[v]);			break;		}			}	printf ("\n");		return OK;}int	push (int   value, int   type){	int	v;	int	t;	int	ret;	if (value == 0 && type ==0) {		ret = pickup (&v, &t);		if ( (v ==0) || ret || t>1)			return EUNKNOWN;	}	if (type == 2) {		ret = pickup (&v, &t);		if (t == 2 && v < value)			drop ();	}		if (++sp >= STACKSIZE)	    return EOVER;	stack[sp].value = value;	stack[sp].type = type;	return OK;}int	pop (int   *value, int   *type){	if (sp < 0) 	   return EEMPTY;	*value = stack[sp].value;	*type = stack[sp].type;	sp --;	return OK;}int	cleanstack (){	sp = -1;	return OK;}int	drop (){	if (sp < 0)		return EEMPTY;	sp --;	return OK;}int	pickup(int   *value, int   *type){	if (sp < 0) 	   return EEMPTY;	*value = stack[sp].value;	*type = stack[sp].type;	return OK;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?