user-0 提问: 这道题做了一段时间发现自己做不出来，就来求助各位了

回复:
user: user-1
content: #include <stdlib.h> #include <stdio.h> #include <string.h>  char *fun(const char *src, const int len, int n) {     char *dest = (char *)malloc(sizeof(char) * len);     int i = 0, j = 0, k = 0;     //扫描前导有多少个*     for(i = 0; i < len; i ++)     {         if(src[i] == '*')         {             k ++;         }         else         {             break;         }     }     //前导小于n填*，之后填字符串内容     for(j = 0; j < len && i < len; j ++)     {         if(j < k && j < n)         {             dest[j] = '*';         }         else         {             dest[j] = src[i];             i ++;         }     }     return dest; }  int main(int argc, char* argv[]) {     char *tmp = "********************ssss***sssfff*****ffffff****";     char *dest = fun(tmp, strlen(tmp), 10);     printf("%s\n", dest);     free(dest);     return 0; }

user: user-2
content: #include <stdlib.h> #include <stdio.h> #include <string.h>  char *fun(const char *src, const int len, int n) { 	int i = 0, j = 0, k = 0; 	//扫描前导有多少个* 	for (i = 0; i < len; i++) 	{ 		if (src[i] == '*') 		{ 			k++; 		} 		else 		{ 			break; 		} 	} 	if (k > n) 	{ 		//若前导*的个数k 大于给定的n，则字符串的长度为:len-(k-n) 		int num = len - k + n + 1; 		char *dest = (char *)malloc(sizeof(char)* num);	 		for (i = 0; i < n; i++) 			dest[i] = '*'; 		for (i = n; i < num - 1; i++) 			dest[i] = src[i + k - n]; 		dest[num] = '\0'; 		return dest; 	} 	else 	{ 		char *dest = (char *)malloc(sizeof(char)* (len+1)); 		for (i = 0; i < len; i++) 			dest[i] = src[i]; 		dest[len] = '\0'; 		return dest; 	} }  int main(int argc, char* argv[]) { 	char *tmp = "**s"; 	char *dest = fun(tmp, strlen(tmp), 3); 	printf("%s\n", dest); 	free(dest); 	return 0; }

user: user-3
content: 仅供参考：//有字符串 //1_22_333,,4444__55555,_666666 //需要解析为 //1 //22 //333 //_ //4444 //55555 //666666 #include <stdio.h> char s[]="1_22_333,,4444__55555,_666666"; char c,*p,*p1; int st; void main() {     st=0;     p=s;     while (1) {         c=*p;         if (0==c) {             switch (st) {             case 1:printf("_\n");    break;             case 2:printf("%s\n",p1);break;             }             break;//         }         switch (st) {         case 0:                  if ('_'==c) {                            st=0;}             else if (','==c) {                            st=1;}             else             {p1=p;                       st=2;}         break;         case 1:                  if ('_'==c) {                            st=1;}             else if (','==c) {printf("_\n");              st=1;}             else             {p1=p;                       st=2;}         break;         case 2:                  if ('_'==c) {*p=0;printf("%s\n",p1);*p=c;st=0;}             else if (','==c) {*p=0;printf("%s\n",p1);*p=c;st=1;}             else             {                            st=2;}         break;         }         p++;     } } //1 //22 //333 //_ //4444 //55555 //666666

user: user-4
content: 这个要看你在啥环境下了，标准C只能一点一点的比较，然后复制。 要是可以用字符串函数库，可以用字符串的的拷贝，链接等做一做。

user: user-5
content: void fun (char str[], int n) { 	int num; 	int len = strlen (str); 	//找到从哪个下标开始不是* 	for (int i = 0; i < len; i++) 	{ 		if(str[i] != '*') 		{ 			num = i; 		} 	} 	int count; 	//进行删除操作 	if (num >= n) 	{ 		for (int i = n, count = num; count <= len; i++,count++) 		{ 			str[i] = str[count]; 		} 	} } 上面那个是错的   删除哪有点问题

user: user-5
content: void fun (char str[], int n) { 	int num; 	int len = strlen (str); 	//找到从哪个下标开始不是* 	for (int i = 0; i < len; i++) 	{ 		if(str[i] != '*') 		{ 			num = i; 		} 	} 	int count; 	//进行删除操作 	if (num >= n) 	{ 		for (int i = n, count = num; i <= count; i++,count--) 		{ 			str[i] = str[count]; 		} 	} }