注册 登录
编程论坛 C++教室

[求助] 这个程序错在哪里??

Black_smart 发布于 2007-10-05 12:49, 457 次点击

C++大学教程上面的一个题目,关于搜索关键字的。VC6.0中编译通过,链接文件的时候出了问题,请指教程序的问题。

#include <iostream>
using namespace std;
int linearSearch( const int [], int, int );
int main()
{
const int arraySize = 100;
int a[ arraySize ], searchKey, element;

for(int x = 0; x < arraySize; x++ ) // create some data
a[x] = 2*x;
cout << "Enter integer search key:" << endl;
cin >> searchKey;
element = linearSearch( a, searchKey, arraySize );

if ( element != -1 )
cout << "Found value in element " << element << endl;
else
cout << "Value not found" << endl;

return 0;
}
int linearsearch( const int arraay[], int key, int sizeofArray )
{
for (int n = 0; n < sizeofArray; n++ )
if( arraay[ n ] == key )
return n;

return -1;
}

3 回复
#2
aipb20072007-10-05 13:00
Check the words spelling carefully.
#3
Black_smart2007-10-05 13:07
I found this error already........ Thanks for aipb2007!!

PS:翻版的C++大学教程上面的错误好多啊,无论是chm还是pdf都是错误满出,- -!

[此贴子已经被作者于2007-10-5 13:08:29编辑过]

#4
csmenglei9512007-10-05 14:03

Ihe diffence between "S" and "s".

1