Find a string array c language

                                                                        String array is an array of pointers, pointers need to use two

                    

#include " the stdafx.h " 
#include <stdio.h> 
#include < String .h> const char * STR [] = { " the Hello " , " ABC " , " applef " , " man " , " C Programming " , " pointer array " };
 const char * = pDEST " array of pointers " ;staticint str_search(constchar*key, const



  


   char ** pstr, int NUM) 
{ 
    int I; 

    for (I = 0 ; I <NUM; I ++ ) 
    { 
        /// / p first pointer array pointer points to the type and so is the second address pointer 
        IF (strcmp (* ++ pstr, Key) == 0 ) 
        { 
            return  0 ; 
        } 

    } 

    return - . 1 ; 

} 


int main () 
{ 

    int RET; 
    RET = str_search (pDEST, STR, the sizeof (STR) / the sizeof ( char * ));
     IF (ret == 0)
    {
        printf("查找成功\n");
    }
    else
    {

    }

    printf("\n");        
    printf("i = %d\n", sizeof(str) / sizeof(char*));

    while (1);

    return 0;
}

 

Guess you like

Origin www.cnblogs.com/nowroot/p/12642411.html