Reputation: 15
I wrote program in C using visual studio 2013 , but i got this error: MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
I don't know what is it mean and how to fix it.this is the code :
#include<stdio.h>
int getArr(int arr[]){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
return n;
}
void putArr(int arr[],int n)
{
for(int i=0;i<n;i++)
printf("%d\t",arr[i]);
printf("\n");
}
void sort(int Arr[],int nArr)
{
for(int i=0;i<nArr-1;i++)
{
int minIndex=i;
for(int j=i+1;j<nArr;j++)
if(Arr[j]<Arr[minIndex])
minIndex=j;
int t=Arr[i];
Arr[i]=Arr[minIndex];
Arr[minIndex]=t;
}
}
int main()
{
int arr[100];
int nArr;
nArr=getArr(arr);
sort(arr,nArr);
putArr(arr,nArr);
return 0;
}
Upvotes: 1
Views: 320
Reputation: 2190
You created a windows application project you should select console Application when creating a new project or if you want to learn win32 programming you can use below links:
https://msdn.microsoft.com/en-us/library/windows/desktop/ff381398(v=vs.85).aspx http://www.catch22.net/
http://pravin.paratey.com/win32/ http://www.win32developer.com/tutorial/windows/windows_tutorial_1.shtm
Upvotes: 1
Reputation: 41097
Your code as written builds fine with VS 2012, VS 2013, or VS 2015 using the command-line tools (via the "Developer Command Prompt for VS xxxx" window).
Windows has three types of main for C/C++ console apps:
main
: This is the traditional ANSI main which takes command-line parameters as char*
wmain
: This is the Unicode main which takes command-line parameters as wchar_t*
_tmain
: This is the _TCHAR
version which can build as either ANSI or Unicode. This is what the default template uses and is set to build as Unicode.
If you changed your void main()
to void wmain()
it would build as well since the default template project settings is set to "Use Unicode Character Set" which on the command-line adds /D_UNICODE /DUNICODE
If you go to Project -> Properties -> General and set Character Set to "Use Multi-Byte Character Set" for All Configurations and All Platforms, then your use of void main()
will successfully link. This uses /D_MBCS
for the command-line instead of /D_UNICODE /DUNICODE
That said, with VS 2013's default project your code builds fine replacing the existing _tmain
with your main
even without changing the character set setting.
Upvotes: 3
Reputation: 11
Visual Studio dont want that user declare variables in case, or for instructions use a declaration a the start of function corpus. Good Luck
#include<stdio.h>
int getArr(int arr[]){
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
return n;
}
void putArr(int arr[],int n)
{
int i=0;
for(i=0;i<n;i++)
printf("%d\t",arr[i]);
printf("\n");
}
void sort(int Arr[],int nArr)
{
int j, i=0;
int t;
for(i=0;i<nArr-1;i++)
{
int minIndex=i;
for( j=i+1;j<nArr;j++)
if(Arr[j]<Arr[minIndex])
minIndex=j;
t=Arr[i];
Arr[i]=Arr[minIndex];
Arr[minIndex]=t;
}
}
int main()
{
int arr[100];
int nArr;
nArr=getArr(arr);
sort(arr,nArr);
putArr(arr,nArr);
return 0;
}
Upvotes: 1