"File has stopped working" when using BGI? - c

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.

Related

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.

cannot find -lws_32.lib while compiling C program

I use Windows and codeblocks 13.12 IDE. I'm writing a C program need functions in <Winsock2.h> (like "WSAStartup" function) ; because Logs showed "Undefined Reference to WSAStartup", I included the command below according to the article WSAStartup link error.
#include <stdio.h>
#include <Winsock2.h>
#pragma comment(lib,"ws2_32.lib")
in case compiling process went wrong while linking library, I had put my program in a project and added "ws2_32.lib" into list of "Link libraries"; however, Logs only shows "cannot find -lws2_32.lib" I'm confused because I have checked that "ws2_32.dll" file exists in my C:\Windows\System32. How should I resolve the problem?

Troubles with VSCode and Windows for a simple C code

I am trying to use VSCode for writing and executing C codes for a course in Windows 10. I installed VSCode and MinGW as the instructions said. I'm trying to run a simple code (print "Hello world"), but when I run the code, the output says "Access denied"
//Test code for C in Windows 10
#include "stdio.h"
#include "stdlib.h"
void main(){
printf("Hello world");
}
I'm not sure if it's gonna solve your problem but when you include header from LibC or any different lib you must use this syntax
#include <stdio.h>
#include <stdlib.h>
If you use < symbol, the preprocessor will look in special path defined by your environement else if you use " symbol, the preprocessor will look in your current directory,

VsCode crtdbg.h not found, how to fix?

Trying to check memory leak tool but Vscode doesn't recognize #include <crtdbg.h>.
Here is the code:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include <stdio.h>
#include <string.h>
int main()
{
char *word = "this still relevant.";
char *mem = (char *)malloc(sizeof(word));
strcpy(mem, word);
printf("%s", mem);
system("pause");
_CrtDumpMemoryLeaks();
}
The compile error:
source.c:4:10: fatal error: crtdbg.h: No such file or directory
#include <crtdbg.h>
How do I properly include crtdbg.h?
PS: I'm using MinGW compiler, everything works except that.
EDIT 1: The solution of that other post doesn't work. If I use the suggested code this appear.
source.c:24:5: error: '_CrtDumpMemoryLeaks' was not declared in this scope
_CrtDumpMemoryLeaks();
EDIT 2: Does anyone uses VsCode with MinGW?
I think that VSCODE couldn't access to header file, crtdbg.h , Pease test a simple following way. Maybe it solved your problem:
1- Run as administrator Developer Command prompt for VS2019. I emphasized run as administrator no run.
2- Type Code .
3- Open project folder.
4- Happy coding and enjoy it.

TURBO C++: Unable to open include file stdio.h

I am trying to compile a simple C program using TUrbo C++ 3.2. But getting the following error: Unable to open include file 'STDIO.h'
I do have these files in INCLUDE library.
Cant help you if you dont post your code. Check if you use #include <cstdio> (not #include "cstdio" or #include <cstdio.h> or #include "cstdio.h".
#include <cstdio> will always work.

Resources