当前位置:   article > 正文

C语言之扫描字符串

C语言之扫描字符串
#include <stdio.h>
#include <string.h>
int main(){
    char strm[70] = "asd asasdfg asd as zx67 asdmklo";
    char strz[8] = "as";
    int len = strlen(strz);
    int count = 0;
    for(int i=0;strm[i]!='\0';i++){
        if(strm[i]==strz[0]){
            char strl[8] = "we";
            for(int j=i,m=0;j<i+len;j++,m++){
                strl[m] = strm[j];
            }
            if(strcmp(strl,strz)==0) {
                count++;
            }
        }
    }
    printf("%d",count);
}

通过母串一个一个推,然后嵌套循环可以扫描出子串,然后实现计数

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号