“致命错误LNK1561:必须定义入口点”

我是Microsoft Visual Studio 2005的新手。我正在编写一个序列搜索程序,当我尝试使用MS VS 2005编译它时,我收到一个错误:

致命错误LNK1561:必须定义入口点

我的代码是:

#include #include int search (int A[], int len, int no) { int i; for (i=0; i<len; i++) if (A[i] == no) return i; return -1; } 

应该添加int main()

 #include #include int search (int A[], int no) { int i; // added sizeof to determine length of array instead of sending the length to function for (i=0; i < sizeof(A); i++) if (A[i] == no) return i; return -1; } int main() { int a[5] = { 1, 2, 3, 4, 5 }; int item = search(a, 3); if (item > 0) { printf("%d\n", item); } else { printf("Element not found!"); } return 0; }