指针形式找出字符串中的某段字符串

#include<stdio.h>
#include <string.h>
char* m_mach(char* a, char ch1, char ch2)
{
char* p = a;
char* ptr1;
char* ptr2;
while (*p != ch1 &amp;&amp; *p != )
{
p++;
}
if (*p == ) 
{
printf(&quot;起始字符不存在&quot;);
return 0;
}

if (*p == ch1)
{
ptr1 = p;
while (*p != ch2 &amp;&amp; *p != )
{
p++;
}
if (*p == )
{
printf(&quot;终止字符不存在&quot;);
return 0;
}
if (*p == ch2)
{
ptr2 = p;
p = ptr1;
while (*ptr1 != ch2)
{
printf(&quot;%c&quot;, *ptr1);
ptr1++;
}
printf(&quot;%c&quot;, *ptr1);
}

}

return p;
}
int main()
{
char ch1, ch2;
char* a[50];
char* p;
printf(&quot;请输入字符串:&quot;);
gets(a);
printf(&quot;请输入起始字符:&quot;);
ch1 = getchar();
printf(&quot;请输入终止字符:&quot;);
getchar();
ch2 = getchar();
p = m_mach(a, ch1, ch2);

return 0;
}
问题:假如创建的函数中建立数组c[],并将起始字符到终止字符中的内容填充到c中,函数返回时数组c[]是否会被覆盖数据,形参不是会消失的吗?此时返回指针c是否在程序结束前内容都不会变化?
2024-01-06
在牛客打卡4天,今天也很努力鸭!
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:23
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务