Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Code does not run after playsound function

ValconGod

New Coder
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<windowsx.h>
#include<MMsystem.h>



int main() {

PlaySound("C:\\Users\\emrec\\Desktop\\sounds\\song.wav",NULL,SND_SYNC);
char uname[20];
int yes,ways1,choice;
printf("Welcome to the Dungeons and Maths \n Press any key to continue.");
}
The playsound function does work but codes after that line doesnt.I see a black screen terminal with song.
What do you guys think?
 
If this is classic C (i.e. not C++) the above code should not compile, as all variable declarations must be at the beginning of a function. But perhaps your compiler is more lenient about it. Otherwise, have you ran the debugger to verify that it you are actually getting to that printf() ? Is this a Windows or Console program ? If it's a Windows program, you will not see that output. Also you are exiting the program immediately after. At least add a line to read the keyboard here.
 
If this is classic C (i.e. not C++) the above code should not compile, as all variable declarations must be at the beginning of a function. But perhaps your compiler is more lenient about it. Otherwise, have you ran the debugger to verify that it you are actually getting to that printf() ? Is this a Windows or Console program ? If it's a Windows program, you will not see that output. Also you are exiting the program immediately after. At least add a line to read the keyboard here.
I moved variables to the top still nothing happens. Also when i switch the printf and playsound printf actually works.Im using the dev c++ terminal if it matters.
 
I moved variables to the top still nothing happens. Also when i switch the printf and playsound printf actually works.Im using the dev c++ terminal if it matters.
It would matter only for the compiler. If you are using a C++ compiler, it is ok to declare variables anywhere. If you are using a classic C compiler, it is only allowed at the beginning of a function. Most modern compilers can do both, they check the file suffix to see if they'll compile C++ or C.
I got it when the music ends it reads the codes. How can i make them work at the same time?
Oh. That was not at all clear from your initial description.
Check if PlaySound has an asynchonous mode. If it doesn't, you will need to use a separate thread.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom