Using winmm library in C - c

i'm trying to make a program in which I can play music i.e mp3 files.I'm trying to do this by using the winmm library.At first when i tried linking it,the compiler gave errors from which i realized that the program hadn't been linked properly with the library but then i added the library file in the linker settings and now the program executes fine(no errors-suggesting that it has been linked properly) but no music is played.I can't figure out what the problem is.I'm currently using codeblocks,which uses gcc compiler.Can anyone explain what the problem is and why the music isn't playing? I'd be grateful if anyone can help me out! :)
my code(it simply prints the text but no music is played):
#include <stdio.h>
#pragma comment (lib, "winmm.a")
#include <windows.h>
#include <mmsystem.h>
int main()
{
printf("Hello world!\n");
mciSendString("play song.mp3",NULL,NULL,NULL);
printf("\nY");
mciSendString("pause song.mp3",NULL,NULL,NULL);
mciSendString("close song.mp3",NULL,NULL,NULL);
printf("\ndone");
return 0;
}

MCI commands return immediately. This means you immediately pause and close the mp3 hardly before playing started. Looking at the documentation you have to use the Wait Flag:
mciSendString("play song.mp3 wait",NULL,NULL,NULL);

Related

How to create a C console application in Visual Studio Code

I haven't found any extension, or tutorial to make and execute a C console application in the VSCode Terminal.
A simple program like
int main()
{
printf("Hello World!");
return 0;
}
And have the output in the VSCode Terminal.
Does someone know how to realize this? And/or are there solutions?
Thanks in advance
Regards
There actually is an extension for c/c++ on VSCode:
When you click the arrow in the top right (to run the file) you will be asked which compiler you want to use. In our case we can use the gcc compiler:
Then you can paste your code into a .c file and run it with the compiler. It should automatically also execute the binary and print your output into the debug-console:
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
Hello World!
You even have a debugger, if you set certain breakpoints!
Extra:
Make sure that you have the correct OS set in the bottom right (in the status bar), so your c code compiles for your machine specifically.

fatal error: studio.h: no such file or directory

I'm trying to learn how to program in C.
I'm simultaneously learning C, C++, & Java. I have also coded in html and javascript successfully making rich websites.
I'm following video lessons on skillshare. Through VirtualBox I've set up a ubuntu installation, created lesson001.c, and attempted to compile it by entering "gcc lesson001.c"
The program:
#include <studio.h>
int main(){
printf("hello, world!\n");
return 0;
}
The error:
lesson001.c:1:10 fatal error: studio.h: no such file or directory.
The instructor is walking through the coding lesson on a pre-configured linux system, so he does have the same errors. It is frustrating that a comprehensive paid lesson set does not include critical setup parameters.
additional info: "gcc -v" returns about 20 lines of information on gcc 9.3.0, so I believe it is installed correctly.
Thank you
Change the #include <studio.h> declaration to #include <stdio.h>. A header file named studio.h does not exist in the standard library.
stdio stands for "standard input/output," and has nothing to do with "studio"! 😀
It should be stdio instead of studio.
stdio stands for Standard Input Output
Correctly formatted code :
#include <stdio.h>
int main(){
printf("hello, world!\n");
return 0;
}

Can't compile C in Devc++

I have tried running a simple piece of C code in DevC++.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b;
printf("Temporary secretary");
return 0;
}
Every time i try to compile it, it makes "makefile.win" and points out an error on line 25.
screenshot
The error message in the build window is telling you exactly what the problem is - you have multiple definitions of main, one in main.c and the other in Untitled2.c.
Based on what you have posted, it's not clear why Untitled2.c is part of the build - I would remove it from the project completely.
In the future, please do not post links to images of screenshots - copy and paste any code (which includes makefiles) and error messages into the body of your question. We can't copy and paste from a screenshot, and chasing random links is unsafe.

How to compile C program in Visual Studio Code?

I installed VSC and wrote this program
#include <stdio.h>
int main( void )
{
printf("Hello world!");
}
Then I installed a C/C++ debugger and I saved the file on the desktop as "hello.c" and magically the syntax became higlighted.
Now I would like to run the program, but can't find a way.
There's no "run" or "build" option anywhere, and if I start the debugging and choose the debugger then I got a new tab named "settings.json" with a couple of brackets waiting for me to write something.
Also in the left I can read that I "have not yet opened a folder". What does it even mean?
And the line #include <stdio.h> is underlined in red, like there's something wrong going on, maybe I have to download the library?
I would do anything to see the output of the program, please help me.
have you added c/c++ and code runner extensions?

Error running *.c file in Eclipse Kepler

I've started programming in C so weeks ago, and I choose Eclipse Kepler as my IDE for C, since I had already used it for programming in some other languages and really liked.
However, after I had installed Cygwin and the C programming tools in Eclipse, I tried to run the old "Hello World" and it didn't work, It didn't appeared anything in the Console, only the message "Terminated".
#include <stdio.h>
int main(){
printf("Hello World!");
return 0;
}
Anyone has any idea what the problem could be?
Thanks to all of you. I tried everything you said but I wasn't able to get my problem solved. I gave up! Right now, i'm using as workspace in eclipse the Cygwin home. I write the program in the Eclipse and run it in the Cygwin command line.
Again, thanks to all for trying to help, it won't be forgotten. You're a really awesome crowd!
Maybe the program was too fast for you to see it?
The window with the program output appeared and disappeared in the blink of an eye.
You could try to prevent that from happening by changing your program to do its stuff AND wait for ENTER before it terminates.
#include <stdio.h>
int main(){
printf("Hello World!");
getchar(); /* simple wait for ENTER, error prone in more complicated programs */
return 0;
}
Note: your original program "prints a string"; this version "prints a string and waits for ENTER". It's a program with different requirements. If you want to keep to your initial requirements, try running the program from the DOS console.
you could try to system("pause") may this can help
#include <stdio.h>
int main(){
printf("Hello World!");
system("pause");
return 0;
}

Resources