zoukankan      html  css  js  c++  java
  • c语言字符串数组的查找

                                                                            字符串数组是指针数组,需要使用二级指针

                        

    #include "stdafx.h"
    #include <stdio.h>
    #include <string.h>
    
    
    
    const char* str[] = { "Hello","abc","applef","man","C程序设计","指针数组" };
    const char* pdest = "指针数组";
    
    
    static int str_search(const char*key, const char**pstr, int num)
    {
        int i;
    
        for (i = 0; i < num; i++)
        {
            //// 指针数组  p首先是个指针  然后指向类型是地址 所以是二级指针
            if (strcmp(*pstr++, key) == 0)
            {
                return 0;
            }
    
        }
    
        return -1;
    
    }
    
    
    int main()
    {
    
        int ret;
        ret = str_search(pdest, str, sizeof(str) / sizeof(char*));
        if (ret == 0)
        {
            printf("查找成功
    ");
        }
        else
        {
    
        }
    
        printf("
    ");        
        printf("i = %d
    ", sizeof(str) / sizeof(char*));
    
        while (1);
    
        return 0;
    }

     

    一勤天下无难事。
  • 相关阅读:
    [iOS 多线程 & 网络
    [iOS 多线程 & 网络
    [iOS 多线程 & 网络
    [iOS 多线程 & 网络
    [iOS 多线程 & 网络
    [iOS UI进阶
    Python基础
    24种编程语言的Hello World程序
    python中的输入和输出
    第一个Python程序
  • 原文地址:https://www.cnblogs.com/nowroot/p/12642411.html
Copyright © 2011-2022 走看看