字符串函数参数传入传出(字符串反转)
生活随笔
收集整理的這篇文章主要介紹了
字符串函数参数传入传出(字符串反转)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
/***
strstr.c
***/
#include<stdio.h>
#include<string.h>//求字符串p中abcd出現(xiàn)的次數(shù)
//自定義函數(shù)接口完成業(yè)務(wù)函數(shù)和main函數(shù)分開(kāi)
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\n");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 != '\0');*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\n",ret);return ret;}printf("count:%d\n",count);return 0;
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/wanghao-boke/p/11604835.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的字符串函数参数传入传出(字符串反转)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: shell编程题(四)
- 下一篇: 杰斯和安妮买哪个好