计算字符串的字符数和查找几个字符串中是否含有特定字符

代码来自于《C与指针》关于指针的介绍

知识点:指针数组越界

  #define NULL   (void*)0

  代码量的积累很重要!

  代码量的积累很重要!

  代码量的积累很重要!

#include<stdio.h>
//#include<stdlib.h>
#include<assert.h>

char str[] = "ABCDEFG";
size_t str_len(char *string);
int str_find(char **strings,char value);
char *strs[6]={"red","yellow","blue","white","black",NULL};

int main()
{
    int tmp;
    tmp = str_len(str);
    char ch;
    printf(" NULL %d\n",NULL);
    //printf(" NULL %d\n",&NULL);   ERR
    printf("%d\n",tmp);
    printf("%d\n",sizeof(strs[0]));

    for(ch=‘a‘;ch<‘z‘;ch++)
        str_find(strs,ch);

    return 0;

}
//查找几个字符串中是否含有某个字符 找到返回1没有返回0
int str_find(char **strings,char value)
{
    char *string;  //当前正在查找的字符串
    char *stringIn;

    while( (string=*strings++) != NULL )    //while( (string=*strings++) == NULL )  粗心!!! 字符串数组越界!!?
    {
        assert(strings != NULL);        //断言 异常处理
        stringIn = string;
        while( *string !=‘\0‘ )
        {
            if( *string++ == value)      //if(*string==value)   粗心!!!
            {
                printf("%c is in the %s\n",value,stringIn);
                return 1;
            }
        }
    }
    printf("can‘t find  %c \n",value);
    return 0;
}

//计算字符串的长度
size_t str_len(char *string)
{
    int length = 0;
    while(*string++ != ‘\0‘)
        length++;
    return length;
}
/*
E:\myDocuments\GUN\sources>gcc Point.c

E:\myDocuments\GUN\sources>a
 NULL 0
7
4
a is in the black
b is in the blue
c is in the black
d is in the red
e is in the red
can‘t find  f
can‘t find  g
h is in the white
i is in the white
can‘t find  j
k is in the black
l is in the yellow
can‘t find  m
can‘t find  n
o is in the yellow
can‘t find  p
can‘t find  q
r is in the red
can‘t find  s
t is in the white
u is in the blue
can‘t find  v
w is in the yellow
can‘t find  x
y is in the yellow

E:\myDocuments\GUN\sources>
*/
时间: 2024-08-28 15:17:09

计算字符串的字符数和查找几个字符串中是否含有特定字符的相关文章

检测字符串中是否含有非法字符js代码

检测字符串中是否含有非法字符js代码:通常情况下,网站输入的字符串内容是需要经过检测的,因为有些字符带有一定的危险性,会对站点带来一定的危害,下面就介绍一下如何检测一个字符串是否含有非法字符,代码如下: function checks(str){ szMsg="[#_%&'\",;:=!^]"; alertStr=""; for(i=1;i<szMsg.length+1;i++){ if(str.indexOf(szMsg.substring

判断一个字符串中是否含有中文字符:

python中的encode和decode: 首先,在Python中字符串的表示是 用unicode编码.所以在做编码转换时,通常要以unicode作为中间编码. decode的作用是将其他编码的字符串转换成unicode编码,比如 a.decode('utf-8'),表示将utf-8编码的字符串转换成unicode编码 encode的作用是将unicode编码的字符串转换成其他编码格式的字符串,比如b.encode('utf-8'),表示将unicode编码格式转换成utf-8编码格式的字符串

判断 sql 中是否含有中文字符-----待验证

select ascii(字段)数字:48-57字母:65-123汉字:123+ select * from t1 where len(unicode(c1)) < 5; 判断c1第一个字符是否是中文,小于5,非中文 SQL判断某列中是否包含中文字符.英文字符.纯数字 一.包含中文字符 select * from 表名 where 列名 like '%[吖-座]%' 二.包含英文字符 select * from 表名 where 列名 like '%[a-z]%' 三.包含纯数字 select

jquery判断字符串中是否包含特定字符的方法总结

方法一:使用indexOf() 和lastIndexOf()方法 案例: var Cts = "bblText"; if(Cts.indexOf("Text") >= 0 ) { alert('Cts中包含Text字符串'); } indexOf用法: 返回 String 对象内第一次出现子字符串的字符位置. strObj.indexOf(subString[, startIndex]) 参数 strObj 必选项.String 对象或文字. subStrin

Java不规则字符串按照逗号分割的解析方法(字段中又含有逗号)

/** * Java字符串逗号分割解析方法 * 本专门针对双引号中还有逗号或者某个字段无双引号的情况而设计的 * 例如要将 字符串 String sss="101,\"a\",\"中国,江苏\",\"b\",\"中国,北京\",1,0,\"c\""按照逗号进行分割解析; * 正确的split的结果是 (101)(a)( 中国,江苏) ( b)( 中国,北京) ( 1)( 0)( c) *

JS验证表单中TEXT文本框中是否含有非法字符

<form id="form" action="" method="post"> <input type="hidden" name="selected" value="" /> <table class="conditionTable"> <tr> <td class="first">用

查找数据库所有表中是否含有特殊敏感信息

哈哈哈哈哈, 要求:查询出数据库中是否含有敏感词汇,比如“境外”.“twitter”.“脸书等”: 刚开始一顿百度,这该怎么查呢,后询问大神,,,,尼玛,,,大神就是大神 操作; 使用navicat,在数据库上右键------>在模式中查询  欧克! 原文地址:https://www.cnblogs.com/irishua/p/11429788.html

WordCount--统计输入文件的字符数、行数、单词数(java)--初级功能

码云地址: https://gitee.com/YuRenDaZ/WordCount 个人PSP表格: PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning 计划 180 120 · Estimate · 估计这个任务需要多少时间 180 120 Development 开发 580 440 · Analysis · 需求分析 (包括学习新技术) 180 60 · Design Spec · 生成设计文档 40 30 · Design Review · 设计复审 (

转载:js实现统计字符串中特定字符出现个数的方法

//js统计字符串中包含的特定字符个数 function getPlaceholderCount(strSource) {   //统计字符串中包含{}或{xxXX}的个数   var thisCount = 0;   strSource.replace(/\{[xX]+\}|\{\}/g, function (m, i) {     //m为找到的{xx}元素.i为索引     thisCount++;   });   return thisCount; }