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.
Related
I'm on the first CS50 lecture and I'm entering the code into VS Code exactly how I thought it was supposed to be, but for some reason I keep getting the errors at the bottom. It keeps telling me when I try to run make helloweb that the make function doesn't exist 😪
Here's the code.
#include <cs50.h>
#include <stdio.h>
int main(void)
{
string answer = get_string("What's your name? ");
printf("Hello, answer\n");
}
I fixed this issue by running cs50 through Codespaces.
Go to https://code.cs50.io/ and log in with GitHub. After that, you should be able to run Codespaces through VS Code natively by installing the codespaces extension for VS Code. Finally, launch https://code.cs50.io/ through a browser and click "Open in VS Code Desktop".
I'm using visual studio code, in window 10 device, and live in a area where internet accessibility is not good.
I have completed of lecturers of first week of cs50x.
Had extracted cs50.h and cs50.c and copy them to C:\msys64\mingw64\include\
Now after running the code, I'm getting undefined reference to 'get_int' and Id returned 1 exit status.
After going through some online solutions, I get this
In your source code, change #include <cs50.h> to #include <cs50.c>
But I'm not finding any <cs50.h> in cs50.c source file instead it has "cs50.h"
I'm not able to understand
How to link cs50 when compiling your code with clang, by using -lcs50
I am using code blocks as my default IDE to code my c programs. but I am constantly getting the error that file has stopped working whenever I compile the following code related to graphics in c programming.
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
main()
{
int gd=0,gm;
initgraph(&gd,&gm,"");
circle(300,200,80);
getch();
closegraph();
}
I am getting no error and no warning. But still I am unable to run this code properly. I have added all the files like library and header files in correct order. Please help me to run this code successfully.
I'm new to programming and currently I'm learning C programming. I'm writing codes on the code blocks and in it using GCC compiler. When I create a new project, (as you know it creates main.c file with it) and due to that I'm not able to compile another file in that project.
File 1:
#include<stdio.h>
int main()
{
int a,b,c,d;
printf("Enter three numbers\n");
scanf("%d%d%d",&a,&b,&c);
d=a;
if(b>d)
d=b;
if(c>d)
d=c;
printf("\n The maximum of three numbers is %d",d);
}
File 2: main.c
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
When I compile the first programme, it shows the following error:
multiple definition of 'main'
first defined here
I've searched every where I could and I'm not able to solve this. In one of the answers here on stack overflow, someone had suggested to write this in
(Project->Build options...->Linker settings (tab))
-Wl,--allow-multiple-definition
When I wrote it, there were no errors. But it wasn't able to run my File 1 and instead, it runs that main.c file. Even when I close the main.c file, it opens there again and runs main.c file which gives the output "Hello World!".
Initially when I was using code blocks there were no such errors. I don't know why this is happening and I've not much knowledge about compilers.
As noted in comments you can only have one main function.
So when you start a new project you need to replace the main.c file with the main.c file you want to use. Or you can edit the 'hello world' main.c program.
When you start a new project in code::blocks you can get a new directory with a simple program that prints 'Hello World'. This file is usually main.c. You need to edit this file or replace it. The reason that code::blocks puts this simple main.c program in the new project is so that you can compile it and test your system without having to write a new program.
Some computer languages allow you to use the same function name for different functions ( which are identified by their parameters and sometimes return types ). That's called overloading. C does not allow this. Functions in C must have unique names.
The main() function is a special one in C as it is used as the standard entry point for applications. That is, the main() function will be called first and your application should start and (typically) end in that function.
As a beginner I would suggest you avoid automated editor features that create and build projects for you. You will miss out on learning how things work doing that. Use an editor to start from empty files and learn how they all connect and how to use the compiler from the command line. The command line is something every beginner should start from, IMO.
It may be harder to learn, but it will give you a much better feel for what is going on.
I guess what you maybe trying to do is have multiple sandbox "gists" that you may wanna run all as their own main function. If that is the case, then just close your project and open the files directly. As long as they are not in a project, they will run fine.
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);