strrev这个函数.
对于一个已经填充好的数组(没有填充满)怎么把这个数组逆序输出啊???
我是这样做的:
char c[100];
char *rs = c;
//往里放些值;(不放满)
//然后要按上面输入的逆序输出;
char *ch = strrev(c);
while(*ch)
{
cout <<*ch;
ch ++;
}
//为什么不行啊??
程序代码:
#include<iostream> using namespace std; void main() { _int64 m, n, tmp, rs; while(scanf("%I64d%I64d", &m, &n)) { char c[100]; char *ch = c; rs = m - n; int i = 0; while((tmp = rs/10) > 0) { if(3 == i) { *ch = ','; // cout <<*ch; ch ++; i = 0; } *ch = rs - tmp*10 + 48; // cout <<*ch; ch ++; i ++; rs = tmp; } if(i == 3) { *ch = ','; // cout <<*ch; ch ++; } *ch = rs + 48; // cout <<*ch; char *cc = strrev(c); while(*cc) { cout <<*cc - 48; cc ++; } printf("\n"); } }#include<iostream> using namespace std; void main() { _int64 m, n, tmp, rs; while(scanf("%I64d%I64d", &m, &n)) { char c[100]; char *ch = c; rs = m - n; int i = 0; while((tmp = rs/10) > 0) { if(3 == i) { *ch = ','; // cout <<*ch; ch ++; i = 0; } *ch = rs - tmp*10 + 48; // cout <<*ch; ch ++; i ++; rs = tmp; } if(i == 3) { *ch = ','; // cout <<*ch; ch ++; } *ch = rs + 48; // cout <<*ch; char *cc = strrev(c); while(*cc) { cout <<*cc - 48; cc ++; } printf("\n"); } }