在函数中用宏定义的itemNum 结果和在主程序中用不一样 在查找函数中一直都是1 主程序中是正常值
数组定义在了主函数中 函数也用了引用。。。
#include <iostream>
#define itemNum(a) sizeof(a)/sizeof(a[0])
//顺序查找:在数组int a[n]中查找值val
//返回true(找到)或false(没有找到)
bool found(int val,int *a,int n) {
for(int i=0,mark=0;i<n;i++)
{
std::cout<<"第"<<i<<"次循环"<<"数组里的值"<<a[i]<<"实际输入的数"<<val<<"数组共有"<<itemNum(a)<<"个数"<<std::endl;
if (a[i]==val)
{
mark=1;
return 1;
}
}
if (mark==0)
return 0;
}
//字符串查找:在字符串s中查找字符c
//返回true(找到)或false(没有找到)
/*
bool found(char c,char *s) {
for(int i=0,mark=0;i<itemNum(s);i++)
{
if (s[i]==c)
{
mark=1;
return 1;
}
}
if (mark==0)
return 0;
}
*/
int main() {
int a[]={12,80,78,62,63,89,5,9,89,23,1,6,33,54,30,97,55};
char s[]="fdsfdsfds234234543543scfxzDSGFD*&ASGFwR12%$^";
int val;
char c;
int n=itemNum(a);
std::cin>>val/*>>c>>c*/;
std::cout<<"数组共有"<<itemNum(a)<<"个数"<<std::endl;
std::cout<<found(val,a,itemNum(a))/*<<found(c,s)*/<<std::endl;
return 0;
}