#include "stdio.h"
size_t _strlen(char* str)
{
if (str==NULL || *str=='\0') return 0;
int count=0;
while (*str++)
{
count++;
}
return count;
}
void scroll_str(char* str,int step)
{
if (str==NULL || *str=='\0' || step<=0) return;
int len=_strlen(str);
int real_step=step%(len-1);
char c=*str;
char* p1=str;
char* p2=str+1;
for (int i=0;i<real_step;i++)
{
*p1=*p2;
p1++;
p2++;
}
*p1=c;
}
void main(void)
{
char a[]="Hello World!";
printf("%s\n",a);
scroll_str(a,10);
printf("%s\n",a);
}
算法待优化