c语言,任意位置插入字符或者字符串
char *insert(char *s1,char *s2,int n) { int len1 = 0, len2 = 0,i,j = 0,k = 0; char str3[100]; if(s1 == NULL) { return NULL; } if(s2 == NULL) { return s1; } len1 = strlen(s1); if(n>strlen(s1)) { return "\0"; } len2 = strlen(s2); for(i = 0;i<n;i++) j++; for(i = 0;i<len1;i++) { str3[k++] = s1[i]; } for ( i = 0; i < len2; i++) s1[j++] = s2[i]; for( i = n; i < len1; i++) s1[j++] = str3[i]; s1[j] = '\0'; return s1; }
空格也算一个字符