//a是一个字符数组,含有n个字符,把字符串a的m个字符以后的部分变为字符串b #include <stdio.h> //判断字符串长度 int len_str(char *poiter) { int n = 0; int i = 0; do{ n++; i++; }while (*(poiter+i) != NULL); return n; } char new_str(int m, char *p1, char *p2) { int i; for (i = 0; i < m; i++){ p1++; } while(*p2 != NULL){ *p1 = *p2; p2++; p1++; } *p1 = NULL; return 0; } void main () { int n; char *poiter; char a[128]; int m; char b[] = "china"; poiter = a; printf ("input a string : "); scanf ("%s", poiter); printf ("%s\n", poiter); n = len_str(poiter); m = len_str(b); if (n > m){ new_str(m, a, b); }else ("input error"); printf("the new string is : %s\n", a); }