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 ...
随机推荐
- PING命令入门详解(转载)
本文转自http://www.linkwan.com/gb/tech/htm/928.htm 1.Ping的基础知识 ping命令相信大家已经再熟悉不过了,但是能把ping的功能发挥到最大的人却并不是 ...
- MSSQLSERVER数据库- 配置数据库邮件配置的操作过程
还是第一次发现数据库可以发邮件.查了一下百度,试了一下,发现可以. 1.简单了解数据库邮件的概念和使用的传输协议及系统体系: 数据库邮件是从 SQL Server 数据库引擎中发送电子邮件的企业解决方 ...
- hadoop 2.0 详细配置教程
http://www.cnblogs.com/scotoma/archive/2012/09/18/2689902.html
- linux快速入门 1.1命令行操作
http://lovesoo.org/linux-command-line-operation.html 1.1命令行操作 目录: <wp_nokeywordlink>Shell简介 &l ...
- mac磁盘满解决方案
背景 : 用mac电脑的人,估计都不习惯去关机吧.mac虽然可以不需要关闭电脑,但是久而久之由于应用软件占用产生缓存文件 or 产生虚拟内容交换文件 or 睡眠镜像文件 and so on. 会占用大 ...
- CircularProgressBar
https://github.com/semicoder/CircularProgressBar https://github.com/amurani/MeterView
- [React Native] Complete the Notes view
In this final React Native lesson of the series we will finalize the Notes view component and squash ...
- SOAP 及其安全控制--转载
原文地址:http://my.oschina.net/huangyong/blog/287791 目录[-] 1. 基于用户令牌的身份认证 2. 基于数字签名的身份认证 3. SOAP 消息的加密与解 ...
- C#数据采集类
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- Enable HTTPS in Spring Boot
Spring-boot-enable-ssl Enable HTTPS in Spring Boot APRIL 14, 2015DRISS AMRI This weekend I answered ...