C 练习实例96

C 语言教程 · 2019-02-22 17:57:36

题目:计算字符串中子串出现的次数 。

程序分析:无。

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int i,j,k,TLen,PLen,count=0; char T[50],P[10]; printf("请输入两个字符串,以回车隔开,母串在前,子串在后:\n"); gets(T); gets(P); TLen=strlen(T); PLen=strlen(P); for(i=0;i<=TLen-PLen;i++) { for(j=0,k=i;j<PLen&&P[j]==T[k];j++,k++) ; if(j==PLen)count++; } printf("%d\n",count); system("pause"); return 0; }

以上实例运行输出结果为:

请输入两个字符串,以回车隔开,母串在前,子串在后:
abca
a
2

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

The Smashing Book

The Smashing Book

Jacob Gube、Dmitry Fadeev、Chris Spooner、Darius A Monsef IV、Alessandro Cattaneo、Steven Snell、David Leggett、Andrew Maier、Kayla Knight、Yves Peters、René Schmidt、Smashing Magazine editorial team、Vitaly Friedman、Sven Lennartz / 2009 / $ 29.90 / € 23.90

The Smashing Book is a printed book about best practices in modern Web design. The book shares technical tips and best practices on coding, usability and optimization and explores how to create succes......一起来看看 《The Smashing Book》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试