反向字符串,如何打印字符串而不是小数? [英] reverse string, how to print string and not decimals?

查看:93
本文介绍了反向字符串,如何打印字符串而不是小数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char * reverse(char * str){

int length = strlen(str);

char * acc [length];

int i;

for(i = 0; i< = length-1; i ++){

acc [length-1-i] = str [i];

}

返回acc;

}


如何打印字符串而不是小数点?如果我在for循环中添加printf,它会打印小数。它们是颠倒的,所以它有效,但是我想要打印字符。

解决方案

ssecorp写道:
< blockquote class =post_quotes>
char * reverse(char * str){

int length = strlen(str);

char * acc [length] ;

int i;

for(i = 0; i< = length-1; i ++){

acc [length-1- i] = str [i];

}

返回acc;

}


如何然后我打印一个字符串而不是小数?如果我在for循环中添加printf,它会打印小数。它们是颠倒的,所以它有效,但我想要打印字符。



向我们展示代码。你所拥有的没有printf()。


Brian




默认用户 < de *********** @ yahoo.comwrote in message

news:6f ************ @ mid.individual.net。 ..


> char * acc [length];



哎呀!


Mark B [Diputsur]写道:


>

" Default User" < de *********** @ yahoo.comwrote in message

news:6f ************ @ mid.individual.net。 ..


char * acc [length];



哎呀!



我当然不写那个。


Brian


char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
return acc;
}

How do I then print a string and not decimals? If I add printf inside
the for loop it prints decimals. they are reversed so it works but I
want to prin chars.

解决方案

ssecorp wrote:

char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
return acc;
}

How do I then print a string and not decimals? If I add printf inside
the for loop it prints decimals. they are reversed so it works but I
want to prin chars.

Show us the code. There is no printf() in what you have.


Brian



"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...

> char* acc[length];

Oops!


Mark B [Diputsur] wrote:

>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...

char* acc[length];


Oops!

I most certainly did NOT write that.

Brian


这篇关于反向字符串,如何打印字符串而不是小数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆