Program builds sucessfully but netbeans shows errors in the includes - c

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.

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.

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.

Xcode for C Implementation - Random Generator - Environment Problems

When you have a few files (see below), how do you get them all working inside Xcode for a C implementation?
These are the files that I’ve been given for this project:
pcg_basic.c
pcg_basic.h
pcg32-demo.c
Project guidelines:
http://www.pcg-random.org/using-pcg-c-basic.html
I am also unclear what should be copied to the main.c file. Can't get a grasp on this.
Apparently you also need to link the code with the pcg_basic.o.
(not sure how to do that, either)
I know the code does work because it was developed by an expert in this space. But everything I try in Xcode ("fails to build"), so I presume it must be the way I've set things up.
What am I doing wrong?
*Student here. I am totally new to programming. Thanks!
error snippet 1
error snippet 2
CODE
/*
* PCG Random Number Generation for C.
* For additional information about the PCG random number generation scheme,
* including its license and other licensing options, visit
* http://www.pcg-random.org
*/
/*
* This file was mechanically generated from tests/check-pcg32.c
*/
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include "pcg_basic.h" <---pcg_basic.h not found
To setup:
in Xcode <File/New/Project...>
choose macOS template tab
from there choose Command Line Tool
in the Wizard choose C as language
Drag & drop your files (pcg_basic.h, pcg_basic.c, pcg32-demo.c) to the Xcode project navigator on the left where main.c resides. A dialog appears: make sure to check Copy items if needed. Then delete main.c in Xcode.
The program builds and runs then.
Demo

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.

Using winmm library in 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);

Resources