• Welcome to Valhalla Legends Archive.
 

Help Fnding Mistake

Started by Dyndrilliac, January 08, 2004, 02:10 PM

Previous topic - Next topic

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!

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)

My code is below.

//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"


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.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Siege

int getch(void);
And from what I have heard using void is bad practice ;)

Kp

#2
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.]
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Adron


MoNksBaNe_Agahnim

#4
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...


#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;
}


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

Siege

Isn't how he uses getch() like that wrong?

\a makes it beep.

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

iago

Yeah, there's nothing wrong with getch().  But main() shouldn't be void.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Skywing

Change /subsystem:windows to /subsystem:console in the linker command-line.