C 语言 查找一个字符串2在字符串1中出现的次数
#include <stdio.h> #include <windows.h> int main() { char a[], b[]; char *temp; int counter = ; memset( a, sizeof(a), ); //清空内存 memset( a, sizeof(b), ); //清空内存 printf( "Please input source string: " ); gets(a); //从缓冲区获取源字符串. printf( "Please input find string: " ); gets(b); //从缓冲区获取查找字符串. temp = a; //将源字符串赋给指针操作. while( temp ) { temp = strstr( temp, b ); //在源字符串中查找
//第一次出现的位置,找到返回所处位置,未找到返回NULL.
if( temp != NULL ) //如果能找到
//,指针偏移查找字符串的长度,然后继续循环,直到查找完成.
{ temp += strlen(b); counter++; } } printf( "find %d times!\n", counter ); //输出找到的个数. system("pause"); return ; }
#include <stdio.h>
#include <string.h> int main()
{ int findCount(char *str1,char const*str2); printf("%d",findCount("","")); return ;
} /**
查找str1中str2出现的次数
*/
int findCount(char *str1,char const*str2)
{ int count=;
char *ptmp=str1; while((ptmp=strstr(ptmp,str2))!=NULL)
{
ptmp+=strlen(str2);
count++;
} return count; }
C 语言 查找一个字符串2在字符串1中出现的次数的更多相关文章
- C语言输入一个整数转化为字符串
将数字转化为对应的字符,可以通过n%10+48来实现,也可以通过n%10+'0'来实现,因为‘0’的ASCII码的数值就是48 因为字符串‘0’ 对应的10进制 整数是48 字符串'9'对应的10进制 ...
- C语言-查找一个元素在数组中的位置
#include<stdio.h> #include <stdlib.h> #include <time.h> int search(int key, int a[ ...
- 给出N个字符串恰好由三位字母(大小写)组成,再给出M个查询字符串,问每个查询字符串在N个字符中出现的次数。
1 #include<cstdio> 2 const int maxn = 100; 3 char S[maxn][5], temp[5]; 4 int hashTable[52 * 52 ...
- C#一个判断子串在父串中出现的次数
/// <summary> /// 计算字符串中子串出现的次数 /// </summary> /// <param name=”str”>字符串</param ...
- hash数组快速查找一个字符串中出现最多的字符,并统计出现的次数
如何快速查找一个字符串中出现最多的字符,并统计出现的次数? 可以使用hash数组,也就是关联数组实现快速查找功能. function seek(str) { var hash = []; var ma ...
- C 语言实例 - 查找字符在字符串中出现的次数
C 语言实例 - 查找字符在字符串中出现的次数 C 语言实例 C 语言实例 查找字符在字符串中的起始位置(索引值从 开始). 实例 #include <stdio.h> int main( ...
- php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpos
php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpossubstr_count($haystack, $needle [,$o ...
- 打开新窗口(window.open) open() 方法可以查找一个已经存在或者新建的浏览器窗口。 语法: window.open([URL], [窗口名称], [参数字符串])
打开新窗口(window.open) open() 方法可以查找一个已经存在或者新建的浏览器窗口. 语法: window.open([URL], [窗口名称], [参数字符串]) 参数说明: URL: ...
- 【C语言】字符串替换空格:实现一个函数,把字符串里的空格替换成“%20”
//字符串替换空格:实现一个函数,把字符串里的空格替换成"%20" #include <stdio.h> #include <assert.h> void ...
随机推荐
- win10中android studio中的terminal不能输入
1 打开CMD窗口右击 2 3 重启电脑,你试试就知道了.
- PTA 5-15 PAT Judge (25分)
/* * 1.主要就用了个sort对结构体的三级排序 */ #include "iostream" #include "algorithm" using nam ...
- Volley使用指南第一回(来自developer.android)
最近闲来想看看android网络方面的东西.google在2013年发布了一个叫做Volley的网络请求框架,我看了一下官网,居然在training里面就有教程.首先,英文的东西看着 还是挺不爽的,特 ...
- Ps切图学习
1.切图的原文件格式为psd,用ps工具打开 2.鼠标点击需要切的图片,会自动选中图层: 3.选择需要切图的图层,右键复制图层 宽高必须为2的倍数 文件-存储为web和设备所用格式 预设选择为png- ...
- sudo: /etc/sudoers is mode 0640, should be 0440解决办法
ubuntu或者CentOS中,/etc/sudoer 的权限为 0440时才能正常使用,否则sudo命令就不能正常使用.出现类似:sudo: /etc/sudoers is mode 0640, s ...
- cocos2dx windows phone平台下CCLabelTTF自己主动换行的实现(2)
前几天发过一篇文章说怎样实现wp8下的CCLabelTTF怎样自己主动换行,后来发现果如预料的那般.效果非常不好.主要是非等宽字体的情况下看着非常糟心.因此再改动了一版.效果要好非常多了. 详细实现事 ...
- [Bootstrap] 2. class 'row' & 'col-md-x' & 'col-md-offset-x'
Usually when desgin a web page, we think building the page in grid. Bootstrap can help us to do that ...
- HDU1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 2014年6月5日 深圳 IBM 安全解决方案会议通知
2014年6月5日 深圳 IBM 安全解决方案会议通知 http://gdtesting.com/news.php?id=191 时间: 2014年6月5日 地点: 深圳大中华喜来登 议程: IBM安 ...
- a链接中关于this的使用
a连接点击事件用 this 时,要用 onclick='click(this)',href='javascript:void()' a连接无法使用,要看看是不是自动变成ie7或者更低