提取字符串

  晚上9点一同学求助,帮忙做一个C语言题目,本来也是懒得动,但看到同学那份焦急的心情,还是勉强接受这个挑战
  
代码实现:
基本思想是将找到地N个字符C后面的字符串,然后在将N~n-1的字符串存储起来
#include <stdio.h>

char tab[]="AAA?BBB?CCC?";
char result[1024];
void getsegment (char *s,char c,int N)
{
	char *p;
	p=s;
	int n=1;
	int i=0;
	while(p!=NULL)
	{
        if(*p++==c)
		{
			n++;
			
			if(n==N)
				break;
		
		}
       
	}
	while (*p!=c)
	{
       result[i]=*p;
	   i++;
	   p++;
	}
  
	printf("The Segment is %s \n",result);
	return;
}

void main()
{
   getsegment(tab,'?',2);

}

结果如下:



猜你喜欢

转载自blog.csdn.net/fengliang191/article/details/38825135