字符串移位:如“abcdefghi”右移2位后变成“cdefghiab”
生活随笔
收集整理的這篇文章主要介紹了
字符串移位:如“abcdefghi”右移2位后变成“cdefghiab”
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
函數(shù)頭:
//pStr 是指向以'\0'結(jié)尾的字符串指針 //steps 是要求移動的步數(shù)void LoopMove(char *pStr, int steps) {//...... }使用庫函數(shù)實現(xiàn):
方法一:
#define MAX_LEN 1000void LoopMove(char *pStr, int steps) {int n=strlen(pStr)-steps;char tmp[MAX_LEN];strcpy(tmp,pStr+n);strcpy(tmp+seps,pStr);*(tmp+strlen(pStr))='\0';strcpy(pStr,tmp); }方法二:
#define MAX_LEN 1000void LoopMove(char *pStr, int steps) {int n=strlen(pStr)-steps;char tmp[MAX_LEN];memcpy(tmp, pStr+n, steps);memcpy(tmp+steps, pStr, n);memcpy(pStr, tmp, n+steps) }?
轉(zhuǎn)載于:https://www.cnblogs.com/sooner/p/3145452.html
總結(jié)
以上是生活随笔為你收集整理的字符串移位:如“abcdefghi”右移2位后变成“cdefghiab”的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle数据库单个数据文件的大小限制
- 下一篇: Web页面上的控件