下面是我自己写的一种方法,防止自己忘记:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define M 100
char *mov(char str1[],int m)
{
char *str2 = "";
int i=0,j=0,n=0;
n=strlen(str1);
str2=(char *)malloc(M);//malloc (n);
for (i=m;i<n;i++)
str2[j++] = str1[i];
for (i=0;i<m;i++)
str2[j++] = str1[i];
return str2;
}
int main ()
{
char str1[M] = "abcdefghijklmn";
char *str2 = "";
int m = 0, n =0;
str2=(char *)malloc(M);
n = strlen (str1);
printf("Please input a num you want insert:");
scanf("%d",&m);
if ( m < n) //this is a judge
{
str2=mov(str1,m);
printf ("output is %s\n",str2);
}
else //if the input "m" > n,exit
printf("input error,exit\n");
return 0;
}