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 ...
随机推荐
- FreeModbus 精简版本(Only RTU) for M128 (Modbus Slave)
1.硬件连接: M128 PD3 INT3/TXD1 ---> PC 232COM Pin 2 PD2 INT2/RXD1 ---> PC 232COM Pin 3 GND ...
- CSS3之边框图片border-image
CSS3中有关border的属性,还有很多,今天我将为大家介绍一个很好玩的属性——Border-image.有了CSS3之边框图片Border-image,我们可以轻松搞定圆角,轻松搞定很多之前难搞的 ...
- 博客搬家啦。请访问我的新底盘www.boyipark.com
博客搬家啦.请访问我的新底盘 www.boyipark.com
- Spring ProxyFactory
ProxyFactory 是 Spring AOP的实现方式之一.下面介绍下ProxyFactory的用法. 1.接口定义 public interface UserReadService { pub ...
- 修改 suse 上的postfix 的日志路径
刚刚搭建的邮件服务器,没过多久硬盘就爆满了,不得已移动存储,包括日志. 移动存储灰常简单,查找 /etc/postfix/main.cf 中的 data_directory / base_direct ...
- 教你50招提升ASP.NET性能(十三):精选技巧集合
(19)A selection of tips 招数19: 精选技巧集合 Including height and width in <img /> tags will allow you ...
- iOS 强制横屏
// // AAAAViewController.m // hengp // // Created by 朱信磊 on 15/2/13. // Copyright (c) 2015年 niit. Al ...
- ubuntu安装mysql后不能远程访问的方法
ubuntu安装mysql后不能远程访问的方法1.mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassw ...
- 重启PHP命令
php-fpm重启 killall php-fpm 再执行(usr/local/php是php的安装目录)/usr/local/php/sbin/php-fpm & /usr/local/ng ...
- 应聘.net开发工程师常见的面试题(四)
1.在Asp.net中所有的自定义用户控件都必须继承自________? 答:Control. 2.在.Net中所有可序列化的类都被标记为_____? 答:[serializable] 3.在.Net ...