VsCode crtdbg.h not found, how to fix? - c

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.

Related

My C Code exe only runs on my PC. How do I Include VCRuntime140.dll in my C code exe

I have recently been getting in C code.
I would like to create a stand alone .exe that can run on a windows PC.
The exe runs on my pc, of course because of the installation. However, on another PC I get an error
> code execution cannot proceed because vcruntime140d.dll was not found
How do I include this dll so that it will run on any PC
Any assistance will be fantastic.
Its a very simple code, see below
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int main(int argc, char* argv[])
{
printf("\n\nHi there.\n\nThis is a .exe test.\n\n If you are seeing this, it is successful.\n\n");
system("pause");
}
I have googled this for a couple of days now, there has not been a real answer to my question.
EDIT after last comment
Here are the settings I have adjusted
I did select x64

error trying to #include headerfile within main function

Newbie question: To my knowledge the way #include works is that it copy-pastes whatever is inside the included file to the designated spot. All I want is to #include a file which only holds a printf().
And while this works perfectly in any online IDE I have tried, in Code::Blocks I receive
error: expected declaration specifiers or '...' before string constant
This is the main file:
#include <stdio.h>
int main(void)
{
#include "null.h"
}
And this is the included null.h:
printf("Hello, world\n");
I have tried #include <stdio.h> above printf() function call as well as calling the file null.c however nothing seems to work. I have searched Google but can't wrap my head around what this error has to do with any of the explanations provided.
edit: I now use gcc via cmd in order to compile which works for me.

Program builds sucessfully but netbeans shows errors in the includes

I have this program it builds but shows some errors in the includes
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
/** These two files are necessary for calling CTOS API **/
#include <ctosapi.h>
/**
** The main entry of the terminal application
**/
int main(int argc,char *argv[])
{
BYTE key;
// TODO: Add your program here //
CTOS_LCDTClearDisplay();
CTOS_LCDTPrintXY(1, 1, "Hello");
CTOS_KBDGet(&key);
exit(0);
}
here's the print of it:
print of netbeans window
Edited:
here's the error:
Cannot find include file <stdlib.h>.
I think I found the problem but how do I solve this
has u can see in the image the system directories that look for includes are wrong because they have "/gneaubi" twice, the question is how do I change this
It seems that problem is coming from Netbeans IDE.
I would suggest to follow this once and check if the problem is rectified.
Right-click your project and go to properties.
In the properties, click run and change the console type to standard output.
P.S: Please provide proper info about the error by hovering mouse on error ballon. Given info is not sufficient currently.

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,

"File has stopped working" when using BGI?

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.

Resources