惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
The Cloudflare Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
L
LangChain Blog
Recent Announcements
Recent Announcements
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
I
InfoQ
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
H
Help Net Security
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
B
Blog RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - LeeXiaoLiang

自己写的一个javascript下拉列表类 jquery1.5.1根据元素ID获取元素对象 jquery向.ashx文件post中文乱码问题的解决 【转】通过在RowDataBound事件中把行索引绑定到控件的CommandArgument,然后在RowCommand事件中取出 - LeeXiaoLiang - 博客园 【转】GridView的RowCommand事件中取得行索引 - LeeXiaoLiang - 博客园 【转】GridView 实现服务器端和客户端全选的两种方法 ASP.NET之GridView数据绑定 - LeeXiaoLiang - 博客园 希尔排序的C语言实现(2) 希尔排序的C语言实现(1) 简单插入排序的C语言实现 堆排序的C语言实现 对于堆排序算法的理解 【转】sqlserver中分页方法集锦 【转】高效的MySQL分页 【摘】完全二叉树 【原创】连接字符串数组 【原创】用C实现Trim()函数 - LeeXiaoLiang - 博客园 【转】浅谈数据库设计技巧 [转]数据库设计范式的理解
【摘】用C实现将数组转换为字符串
LeeXiaoLiang · 2010-08-05 · via 博客园 - LeeXiaoLiang

代码

#include <stdio.h>
#include 
<stdlib.h>char *digitToAlpha (int val, char *buf, unsigned radix);int main(int argc, char *argv[])
{
  
int iNum=1000;
  
char strNum[10]="";
  digitToAlpha(iNum,strNum,
10);
  printf(
"%s\n",strNum);
  
  system(
"PAUSE");    
  
return 0;
}
/*
功能:将数值转换为字符串
参数:第一个是要转化的整数   
     第二个是转化后的字符串
     第三个是要转化整数的基数,就是说如果基数是10,就可以直接转化,如果不是10,是其他值(2-36之间),则先把该整数转化为该基数的数后,再转化为字符串
*/
char *digitToAlpha (int val, char *buf, unsigned radix) 

    
char *p; /* pointer to traverse string */ 
    
char *firstdig;/* pointer to first digit */ 
    
char temp; /* temp char */ 
    unsigned digval; 
/* value of digit */ 

    p 

= buf; if(val<0)
    { 
        
/* negative, so output '-' and negate */ 
        
*p++= '-'
        val 
= (unsigned long)(-(long)val); 
    } 

    firstdig 

= p;/* save pointer to first digit */ do { 
        digval 
= (unsigned)(val%radix); 
        val 
/=radix; /* get next digit */ /* convert to ascii and store */ 
        
if (digval > 9
            
*p++ = (char) (digval - 10 + 'a'); /* a letter */ 
        
else 
            
*p++ = (char) (digval + '0'); /* a digit */ 
    } 
while(val > 0); /* We now have the digit of the number in the buffer, but in reverse 
    order. Thus we reverse them now. 
*/ *p-- = '\0'/* terminate string; p points to last digit */ do 
    { 
        temp 
= *p; 
        
*=*firstdig; 
        
*firstdig= temp; /* swap *p and *firstdig */ 
        
--p; 
        
++firstdig;     /* advance to next two digits */ 
    } 
while (firstdig < p); /* repeat until halfway */ return buf; 
}

该程序的测试环境:

WinXPSP2,Dev C++ 4.9.9.2