www.pudn.com > MessageQueue.zip > Itoa.c
/*
Copyright (C) 2004 Liu Ge
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*******************************************************************
* Library functions
*******************************************************************/
const char * IntToStr(int value, char * sz)
{
int i, dividend;
if( value == 0 )
{
sz[0] = '0';
sz[1] = 0;
return sz;
}
if( sizeof(int) == 2 )
{
dividend = 10000;
}
else if( sizeof(int) == 4 )
{
dividend = (int)1000000000L;
}
else
{
return 0;
}
for(i = 0;dividend > 0;)
{
int n = value/dividend;
if( n != 0 || i != 0 )
{
sz[i++] = (char)( n + '0' );
value %= dividend;
}
dividend /= 10;
}
sz[i] = 0;
return sz;
}