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

#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天,今天也很努力鸭!
全部评论

相关推荐

点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-17 14:38
干个蛋,干不了一点!!!!我真服了,还没搞完,很急。&nbsp;今天ddl,活没干完直接通宵,刺激。食堂很好吃,感觉离职的时候会胖10斤。mt喜欢能直接干活的,没空指导我,很难受。每个人都是笑嘻嘻的,但是从他们聊天中都能感受到各种试探,我有点慌了大家真的nb,都能准时完成工作下班,我羡慕啊!!!!!每天好累,想离职了💔
牛客26106072...:能去字节实习说明你的能力挺被认可的,实习中的这种累更有利于个人职场成长,试着当熬夜打游戏一样熬一熬,实习的意义就是看自己的差距和适应能力,总比等到工作时各种不适应辞职要好得多吧?
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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