c语言库函数大全文库,C语言库函数源代码

41528d3028836879cd698677c3999917.gifC语言库函数源代码

C语言库函数源代码 strstr ( )/* -- C语言库函数源代码 - */ /* 得到s1中第一次包含s2字符串的位置指针。 */ #include stdlib.h char * my_strstr(const char *s1,const char *s2) { if (*s1 == 0) { if (*s2) return (char *) NULL; return (char *) s1; } while (*s1) { size_t i; i = 0; while (1) { if (s2[i] == 0) { return (char *) s1; } if (s2[i] != s1[i]) { break; } i++; } s1++; } return (char *) NULL; } int main() { char *str1 = ammana_babi; char *str2 = babi; char *p; if( (p = my_strstr(str1,str2)) == NULL) printf(Cant find the string \%s\!\n,str2); else printf(Find the string \%s\!\n,p); str1 = abc; str2 = def; if( (p = my_strstr(str1,str2)) == NULL) printf(Cant find the string \%s\!\n,str2); else printf(Find the string \%s\!\n,p); system(pause); return 0; } strpbrk ( )/* -- C语言库函数源代码 - */ /* 得到s1中第一个且是s2中字符的位置指针。 */ #include stdlib.h char * my_strpbrk(const char *s1 ,const char *s2) { const char *c = s2; if (!*s1) return (char *) NULL; while (*s1) { for (c = s2; *c; c++) { if (*s1 == *c) break; } if (*c) break; s1++; } if (*c == \0) s1 = NULL; return (char *) s1; } int main() { char *str1 = ammana_babi; char *str2 = babi; char *p; if( (p = my_strpbrk(str1,str2)) == NULL) printf(No same character!\n); else printf(%c\n,*p); str1 = abc; str2 = def; if( (p = my_strpbrk(str1,str2)) == NULL) printf(No same character!\n); else printf(%c\n,*p); system(pause); return 0; } strcspn ( )/* -- C语言库函数源代码 - */ /* 得到s1中第一个且是s2中字符的字符位置。 */ int my_strcspn(const char *s1 ,const char *s2) { const char *s = s1; const char *p; while (*s1) { for (p = s2; *p; p++) { if (*s1 == *p) break; } if (*p) break; s1++; } return s1 - s; } int main() { char *str1 = ammana_babi; char *str2 = babi; int offset; if((offset = my_strcspn(str1,str2)) = strlen(str1)) printf(Cant find the same character!\n); else printf(%c\n,*(str1 + offset)); str1 = abc; str2 = def; if((offset = my_strcspn(str1,str2)) = strlen(str1)) printf(Cant find the same character!\n); else printf(%c\n,*(str1 + offset)); system(pause); return 0; } strspn ( )/* -- C语言库函数源代码 - */ /* 得到s1中第一 个且不是s2中任意字符的字符位置。 */ int my_strspn(const char *s1 ,const char *s2) { const char *s = s1; const char *p; while (*s1) { for (p = s2; *p; p++) { if (*s1 == *p) break; } if (*p == \0) break; s1++; } return s1 - s; } int main() { char *str1 = ammana_babi; char *str2 = &

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值