52 (make the tail* not more than n, and delete the extra part*)

52 date: 2021.3.15
Insert picture description here
Key points:

The detailed code is as follows:

#include <stdio.h>
void  fun( char *a,int  n )
{
    
    
	/*
		analyse:


	*/
	int i = 0, k = 0;

	char *p, *t;
	p=t=a; //将指针移动到字符串末尾
	while(*t)
		t++;
		t--;

	while(*t == '*')//指针指向前一个,同时标量k增加1
	{
    
    
		k++; //末尾*号个数
		t--;
	}
	if(k>n)
	{
    
    
		while(*p && p<t+n+1)
		{
    
    
			a[i] = *p;
			i++;
			p++;
		}

		a[i] = '\0';
	}

	/*
	int i,j;

	//求长度
	for(i = 0; a[i] != '\0'; i++);

	//求*起始位置
	for( j = i-1; a[j] == '*'; j--);

	if(++j > n)
		*a = a[j-n];

	*/

}

void main()
{
    
      char  s[81];  int  n;
   void NONO (  );
   printf("Enter a string:\n");gets(s);
   printf("Enter n :  ");scanf("%d",&n);
   fun( s,n );
   printf("The string after deleted:\n");puts(s);
   NONO();
}
}

Guess you like

Origin blog.csdn.net/weixin_44856544/article/details/114859731