Valhalla Legends Forums Archive | C/C++ Programming | Help Fnding Mistake

AuthorMessageTime
Dyndrilliac
I just recently started learning c++, and I was making a very small simple Win32 Console App to Say the following:

[quote]
Hi!
Beep!
[/quote]

And the "Beep!" would be followed by a beeping sound, than it would wait for you to press a key. I came up with the following errors:

[quote]--------------------Configuration: Practice - Win32 Debug--------------------
Compiling...
Practice.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/Practice.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Practice.exe - 2 error(s), 0 warning(s)[/quote]

My code is below.

[code]//Libraries
#include <iostream.h>
#include <conio.h>

//Functions
void main()
{ // Start Code Body For Function "main"
   cout<<"Hi."<<endl;
   cout<<"Beep!\a"<<endl;
   getch();
} // End Code body For Function "main"[/code]

As far as I could tell,a ccording to the tutorials I found my code is correct. if it matters I'm using MSVC++ 6.0. Any help finding my mistakes would be appreciated.
January 8, 2004, 8:10 PM
Siege
int getch(void);
And from what I have heard using void is bad practice ;)
January 8, 2004, 8:43 PM
Kp
Your compiler has decided that you're designing a GUI program. GUIs have their entry point at WinMain, while text interface programs use the entry point 'main'. So, aside from having a horribly incorrect prototype for main, your C code is fine. Your project files will need to be modified to reflect a console application; never having tried, I'm not even sure if you can modify them. You might have to create a new empty project (Select 'Win32 console application') and then add your existing source to that.

[Edit: Siege posted while I was typing. I'd be curious to see what he thinks is wrong, because the supplied information seems totally irrelevant.]
January 8, 2004, 8:44 PM
Adron
[quote author=Kp link=board=30;threadid=4647;start=0#msg38857 date=1073594677]
I'm not even sure if you can modify them.
[/quote]

You can.
January 8, 2004, 9:02 PM
MoNksBaNe_Agahnim
not sure what \a does but ya int main() is always better than void.

And not sure if you have practiced loops at all but i have always liked and used while/do while loops instead of getch()... such as...

[code]
#include <iostream.h>

int main()
{
int num;

do{
cout << "Hi." << endl;
cout << "Beep!" << endl << endl;

cout << "Input 1 to quit, any other number to "
<< "re-run program";
cin >> num;
}while(num != 1); /* runs program until num is equal to one*/

return 0;
}
[/code]

For a program this small a do while loop is really just extra work, but when you get to bigger stuff it will be nice to already have experience with it
January 8, 2004, 9:28 PM
Siege
Isn't how he uses getch() like that wrong?

\a makes it beep.
January 8, 2004, 9:56 PM
MoNksBaNe_Agahnim
nah the way he used getch(); is fine, all it is doing it pausing the program until you hit any key which closes it
January 8, 2004, 10:04 PM
iago
Yeah, there's nothing wrong with getch(). But main() shouldn't be void.
January 8, 2004, 11:33 PM
Skywing
Change /subsystem:windows to /subsystem:console in the linker command-line.
January 9, 2004, 6:05 AM

Search