本文介绍了反转C中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个用于显示反向字符串的ac程序,以显示每个字符之间的字符"x",例如:(oxlxlxexh)

how to write a c program for display reverse string with characters "x" in between each character eg:(oxlxlxexh)

推荐答案

char word[]="hello";
/*
so the characters...
*/
word[0] = ''h'', word[1] = ''e'', word[2] = ''l'', word[3] = ''l'', word[4] = ''o''
/*
if you want to reverse that, what''s the simplest way? ...::cough cough:: _index_ ::cough::
*/
word[4] = ''o'', word[3] = ''l'', ...
/*
Of course, you can add loops to make that more efficient code

Now to add the ''x'' character, well, that''s easy too... just transfer onto a larger array and add those extra characters into it...  to make it a bit more flexible, look at dynamic memory allocation of character arrays using malloc() and free()
*/



这篇关于反转C中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 16:53
查看更多