在主函数中输入一个字符串,在输入一个字符,编写函数delete(),将字符串中该字符删除,不用指针

在主函数中输入一个字符串,在输入一个字符,编写函数delete(),将字符串中该字符删除,不用指针函数

#include<stdio.h>

#include<string.h>

int strdelete(char *d, char *s)

{

int i, j, k, s1, s2;

s1 = strlen(s);

s2 = strlen(d);

for(i=0, k=0; i<=s2-s1; i++)

{

for(j=0; j<s1; j++)

if(d[j+i]==s[j]) k++;

// printf("%d\n", k);

if(k==s1)

{

for(j=i+s1; j<=s2;  j++, i++)

{

//printf("%d %d\n", j, i);

d[i] = d[j];

}

return 1;

}

}

return 0;


}

int main()

{

char s1[100], s2[100];

gets(s1);

gets(s2);

if(strdelete(s1, s2))

puts(s1);

else printf("没有相同字符串\n");


}

//有问题的话 继续追问吧


追问

老师要求不用指针函数

好纠结啊

追答

int strdelete(char d[], char s[])
改成这样也可以

追问

谢谢

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网