我是靠谱客的博主 称心泥猴桃,这篇文章主要介绍在一组字符中查找,现在分享给大家,希望可以做个参考。

#include <iostream>
using namespace std;
#define SCUESS 1
#define FALSE
0
int find_char( char **strings,char value )
{
char *string;
while( (string = *strings++) != NULL )
while( *string != ''){
if( *string++ == value )
return SCUESS;
}
return FALSE;
}
main(void)
{
char *str[] = {"Beijing","Chengdu",NULL};  //字符数组的表示
	cout << find_char(str,'C') << endl;
}


 

版本二:

#include <iostream>
#include <assert.h>
using namespace std;
#define SCUESS 1
#define FALSE
0
int find_char( char **strings,char value )
{
assert( strings != NULL );
while( *strings != NULL ){
while( **strings != ''){
if( *(*strings)++
== value)
return SCUESS;
}
strings++;
}
}
main(void)
{
char *str[] = {"Beijing","Chengdu",NULL};
cout << find_char(str,'B') << endl;
}

在版本二中,不需要拷贝每一个字符串的的指针,但是,这个程序有个副作用,就是破坏了这个指针数组。

最后

以上就是称心泥猴桃最近收集整理的关于在一组字符中查找的全部内容,更多相关在一组字符中查找内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部