PlaySound not working?

So i've included the winmm lib inside of CODE::BLOCKS.
I also set my file in this directory C:\buzz.wav its as simple as it can get.

My code is this

1
2
3
4
5
6
7
8
9
#include <windows.h>
#include <stdio.h>

int main()
{
    PlaySound("C:\buzz.wav", NULL, SND_ASYNC);
    return 0;

}


Why isn't it playing?
Hey guys, for anyone who's interested, I've found the solution to my problem.

The reason why it wouldn't play is because it needs two slash "\" symbols. Here's my new code.

1
2
3
4
5
6
7
8
9
10
11
#include<iostream>
#include<windows.h>
#include<mmsystem.h>
#include<stdlib.h>
using namespace std;
int main (char argc)
{
      PlaySound(TEXT("C:\\buzz.wav"), NULL, SND_FILENAME | SND_ASYNC); // remember you need 2 slashes these "\\"
      system("pause");
      return 0;
}


It works :) Also remember you need to pause to stall the program somehow! Without the "system("PAUSE")" , it would not of worked!
Last edited on
Topic archived. No new replies allowed.