【问题标题】:"fatal error LNK1561: entry point must be defined"“致命错误 LNK1561:必须定义入口点”
【发布时间】:2015-11-23 10:30:49
【问题描述】:

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

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

我的代码是:

#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()。

标签: c linker visual-studio-2005


【解决方案1】:

应添加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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多