反向字符串,如何打印字符串而不是小数? [英] reverse string, how to print string and not decimals?
问题描述
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屋!