|
<p>程序实现自动编号</p>
<p><img src="http://img.baidu.com/img/iknow/icn_point.gif"> 悬赏分:0 -</p>
<p>解决时间:2010-10-29 12:50</p>
<p>我要实现 0001,0002,0003-----0010,0011,0013-----0100,0101</p>
<p>如何设计此程序啊?C语言,PHP都可以的?</p>
<p>提问者: purpleask - 四级</p>
<p>最佳答案</p>
<p>C语言可以使用static 变量</p>
<p>#include <stdio.h></p>
<p>#include <string.h></p>
<p>int getindex();</p>
<p>void strFormat(int i,char*);</p>
<p>int main()</p>
<p>{</p>
<p>//四位数</p>
<p>char buff[4]={0};</p>
<p>int i = getindex();</p>
<p>printf("i=%d\n",i);</p>
<p>strFormat(i,buff);</p>
<p>i = getindex();</p>
<p>printf("i=%d\n",i);</p>
<p>strFormat(i,buff);</p>
<p>return 1;</p>
<p>}</p>
<p>int getindex()</p>
<p>{</p>
<p>static id =1000;</p>
<p>return id++;</p>
<p>}</p>
<p>void strFormat(int i,char *buff)</p>
<p>{</p>
<p>sprintf(buff,"%04d",i);</p>
<p>printf("格式化后=%s\n",buff);</p>
<p>}</p>
<p>0</p>
<p>回答者:</p>
<p><img src="http://img.baidu.com/img/iknow/icon_taojin.gif"></p>
<p>asmfox - 四级 2010-10-17 16:23</p>
<p>我来评论>></p>
|
|