0

I was running a simple linear search program on VS Code using the MinGW compiler for cpp,

Here is the code:

#include<iostream>
using namespace std;



int main()
{
int a[10]={01,56,38,29,50,45,38,92,67,53};
int item,loc=NULL;
cout<<"Enter the number you want to enter: ";
cin>>item;
int i=9;
while (i)
{
    if(a[i]==item)
    {
        loc=i;
        i=0;
    }
    else
    {
        i--;
    }

}
if(loc!=NULL)
{
    cout<<"The element wa found on the location "<<loc<<endl;
}
else{
    cout<<"The element was not present in the array";
}

return 0;
}

And here is the error that im getting:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

I'm really screwed up with this error as I don't get this error for other files but I get for the file on which I'm running this code. Please help me fix this error.

Aditya Johorey
  • 53
  • 1
  • 1
  • 4
  • Edit your question and add the lines of text that are above the error message so we can see the build commands. I assume you have exactly 1 source file. – drescherjm Sep 26 '21 at 15:27
  • add `-mconsole` to your compilation command line. Got to be a duplicate for this ... – Richard Critten Sep 26 '21 at 15:30

0 Answers0