• 字符串函数参数传入传出(字符串反转)


    /***
    strstr.c
    ***/
    #include<stdio.h>
    #include<string.h>
    
    //求字符串p中abcd出现的次数
    //自定义函数接口完成业务函数和main函数分开
    int getCount(char *mystr,char *sub,int *ncount)
    {
    
        int ret = 0;
        if(mystr == NULL || sub == NULL || ncount == NULL)
        {
        ret = -1;
        printf("one of point is NULL
    ");
        return ret;
        }
    
        int tmpCount = 0;
        char *p = mystr;  //不要轻易改变形参的值
    
        do
        {
        p = strstr(p,sub);
        if(p != NULL)
        {
            tmpCount++;
            p = p +strlen(sub);
        }
        else
        {
            break;
        }
        }while(*p != '');
    
        *ncount = tmpCount;   //间接赋值是指针存在的最大意义
        return ret;
    }
    
    
    int main()
    {
        int ret = 0;
        char *p = "abcd11122abcd3333abcd3456abc";
        int count = 0;
        char sub[] = "abcd";
    
        ret = getCount(p,sub,&count);
        if(ret != 0)
        {
        printf("getCount error ret:%d
    ",ret);
        return ret;
        }
    
        printf("count:%d
    ",count);
        return 0;
    }
  • 相关阅读:
    成长篇之代码灵异事件
    idea快捷键
    java环境配置常用链接
    MySQL分区
    English 动词篇
    仿stl+函数模板
    java 数组复制
    拓扑排序(Topological Sorting)
    2017蓝桥杯第十题(k倍区间)
    翻译NYOJ
  • 原文地址:https://www.cnblogs.com/wanghao-boke/p/11604835.html
Copyright © 2020-2023  润新知