关于 搜索字符 函数 是否会破坏指针 数组
搜索字符串里的字符:
版本一:
/*** Given a pointer to a NULL-terminated list of pointers, search** the strings in the list for a particular character.*/#include <stdio.h>#define TRUE 1#define FALSE 0intfind_char( char **strings, char value ){ char *string; /* the string we're looking at */ /* ** For each string in the list ... */ while( ( string = *strings++ ) != NULL ){ /* ** Look at each character in the string to see if ** it is the one we want. */ while( *string != '\0' ){ if( *string++ == value ) return TRUE; } } return FALSE;}
/*** Given a pointer to a NULL-terminated list of pointers, search** the strings in the list for a particular character. This** version destroys the pointers so it can only be used when** the collection will be examined only once.*/#include <stdio.h>#include <assert.h>#define TRUE 1#define FALSE 0intfind_char( char **strings, int value ){ assert( strings != NULL ); /* ** For each string in the list ... */ while( *strings != NULL ){ /* ** Look at each character in the string to see if ** it is the one we want. */ while( **strings != '\0' ){ if( *(*strings)++ == value ) return TRUE; } strings++; } return FALSE;}