简体   繁体   English

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

[英]“fatal error LNK1561: entry point must be defined”

I'm very new with Microsoft Visual Studio 2005. I'm writing a sequence search program, when I try to compile it using MS VS 2005, I get an error: 我是Microsoft Visual Studio 2005的新手。我正在编写一个序列搜索程序,当我尝试使用MS VS 2005对其进行编译时,出现错误:

fatal error LNK1561: entry point must be defined 致命错误LNK1561:必须定义入口点

My code is: 我的代码是:

#include<stdio.h>
#include<conio.h>

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() should be added: 应该添加int main()

#include<stdio.h>
#include<conio.h>

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM