0

I am building a Visual Studio C++ function for a school project. It is giving me error codes LNK1120 and LNK2019, my program is:

#include "stdafx.h"
#define m 40

int max_zero_len(int arr[], int x, int* max_len);

void _main()
{
    int arr[m];
    int i, x=40, place,Mlen=0;
    srand((unsigned int)time(NULL));
    for (i = 0; i < m; i++)
    {
        arr[i] = rand() % 3;
        printf("%d ", arr[i]);
    }
    place = max_zero_len(arr, x,&Mlen);
    if (Mlen)
    printf("the max zero is:%d and the position is:%d\n", Mlen,place);
    else printf("an array does not sequence of zero\n");
}

int max_zero_len(int arr[], int x, int* max_len)
{
    int zcounter = 0, j,place=0;
    for (j= 0; j< m; j++)
    {
        if (!arr[j])
            zcounter++;
        else
        {
            if (zcounter > *max_len)
            {
                *max_len = zcounter;
                place = j - zcounter + 1;       //position of sequence
            }
            zcounter = 0;
        }
    }
    return place;
}

The errors are:

Error   1   error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup   E:\c++\lab8\tar3\tar3\MSVCRTD.lib(crtexe.obj)   tar3

Error   2   error LNK1120: 1 unresolved externals   E:\c++\lab8\tar3\Debug\tar3.exe 1   1   tar3

When I debug there are no errors. The errors only occur when I run the program. How can I fix the errors?

CocoNess
  • 4,213
  • 4
  • 26
  • 43
Igal Dana
  • 1
  • 1
  • Fixed grammar, added tags to include the programming language used, I formatted the question to separate out the error messages from the text. I edited the title to explain more clearly what the question is asking – CocoNess Dec 20 '16 at 05:40
  • 1
    Remove the underscore from `_main` and make its return type `int` not `void`. – Retired Ninja Dec 20 '16 at 05:44

1 Answers1

1

You entry function needs to have the following name and return type:

int main()

The linker is expecting to find a symbol with this name and is failing to find it.

Mikel F
  • 3,567
  • 1
  • 21
  • 33