字符逆序存放

作者在 2011-05-09 13:42:59 发布以下内容
#include <stdio.h>
#include <string.h >
void fun(char str[])
{
    int i;
for (i=strlen(str)-1;i>=0;i--)
printf("%c", str[i]);
printf("\n");
}
void main()
{
char str[81];
printf("input the string :\n");
scanf("%s",str);
fun(str);
printf("%s\n",str);
}
默认分类 | 阅读 1443 次
文章评论,共9条
杨卫静
2011-05-09 20:00
1
你这叫逆序输出,而不叫逆序存放…
杨卫静
2011-05-09 20:00
2
你这叫逆序输出,而不叫逆序存放…
tayuqitan
2011-05-10 22:07
3
这是逆序输出,在内存中,并没有把它逆序存放了。并且你的代码,有局限行,不能接受空格的输入,接受函数应用puts()。
tayuqitan
2011-05-10 22:08
4
错了。不是puts()<br />
而是gets()。
宇智波曌(作者)
2011-05-13 12:44
5
谢啦
p8x8x8
2011-05-20 11:15
6
个人觉得意义不大
宇智波曌(作者)
2011-05-27 12:05
7
<div class="quote"><span class="q"><b>p8x8x8</b>: 个人觉得意义不大</span></div>初学,望见谅!
kemoo
2011-06-04 11:17
8
格式写得不好
lianjiecuowu
2011-06-10 08:10
9
#include &lt;iostream&gt;<br />
using namespace std;<br />
int main()<br />
{<br />
&nbsp; &nbsp; int i;<br />
&nbsp; &nbsp; int n;<br />
&nbsp; &nbsp; int s(0);&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//s为倒置后的整数<br />
&nbsp; &nbsp; cout&lt;&lt;&quot;请输入一个整数:&quot;&lt;&lt;endl;<br />
&nbsp; &nbsp; cin&gt;&gt;n;<br />
&nbsp; &nbsp; for(i=0;i&lt;10;i++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(n&gt;0)<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;s=s*10+n%10;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;n/=10;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else break;<br />
&nbsp; &nbsp;&nbsp; &nbsp; <br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp;&nbsp;&nbsp;cout&lt;&lt;i&lt;&lt;&quot;&nbsp; &nbsp;倒置后的数为:&quot;&lt;&lt;s&lt;&lt;endl;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //i为判断整数的位数的变量<br />
&nbsp; &nbsp; system(&quot;pause&quot;);<br />
&nbsp; &nbsp; return 0;<br />
}
游客请输入验证码
文章分类
文章归档