PlaySound in C++ Console application?

How can I play sounds without freezing the console? If you Google for PlaySound this is the first result: fdwSound … SND_ASYNC The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL. You should familiarise yourself with search … Read more

%i or %d to print integer in C using printf()?

They are completely equivalent when used with printf(). Personally, I prefer %d, it’s used more often (should I say “it’s the idiomatic conversion specifier for int“?). (One difference between %i and %d is that when used with scanf(), then %d always expects a decimal integer, whereas %i recognizes the 0 and 0x prefixes as octal and hexadecimal, but no sane programmer uses scanf() anyway so this should not be a concern.)

How to keep the console window open in Visual C++?

Start the project with Ctrl+F5 instead of just F5. The console window will now stay open with the Press any key to continue . . . message after the program exits. Note that this requires the Console (/SUBSYSTEM:CONSOLE) linker option, which you can enable as follows: Open up your project, and go to the Solution Explorer. If you’re following along with me … Read more