#include<stdio.h>
#define TRUE 1
#define FALSE 0
int find_char(char **strings ,char value)
{
char *string;
while((string = *strings++)!=NULL)
{
while(*string !='\0')
{
if(*string++ == value)
return TRUE;
}
}
return FALSE;
}
这是一个很简单的函数。。
函数的参数:strings和value,strings是指向指针数组(不是数组指针哦,数组存的都是指针)的指针,value是我们要查找的相应的字符值(字符在内存中存储都是值,ASCII码)。。。这里需要注意的两点,第一:是要定义一个string指针来暂存每个字符串的指针,一面破坏原指针数组(当然可以再传入参数前加入const,告诉编译器,更改指针变量的值需要报错,如下代码),第二点,循环终止标志是NULL。
#include<stdio.h>
#define TRUE 1
#define FALSE 0
int find_char(char const * const*strings ,char value)
{
char *string;
while((string = *strings++)!=NULL)
{
while(*string !='\0')
{
if(*string++ == value)
return TRUE;
}
}
return FALSE;
}
char const * const*strings,这里需要理解他的意思:以我个人的理解,如果有错,请告之谢谢。第一个const是说明,字符串不允许被更改,第二个说明指针数组中的指针指向的子字符串地址不允许更改。
如果对const的用法不了解,可以参考相应的文档。