Allegro error in DevC++ - c

I am running the latest DevC++ 5.5.3 and I need to use the Allegro 5.0.4 so I downloaded it from devpaks and install it common way. But when I want to run the project with allegro the compiler show me error "allegro.h: No such file or directory". I was looking for the answer but I haven't found the relevant one. And what more I have to use DevC++.
#include <stdio.h>
#include <allegro.h>
int main(void)
{
allegro_init();
allegro_message("Hello World");
return 0;
}
END_OF_MAIN()
Linker is set to -lalleg

Allegro 5 is not backward compatible with Allegro 4. It is a brand new library made by the same people.
Your code snippet is for Allegro 4.
The equivalent is:
#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
int main(void)
{
al_init();
// al_init_native_dialog_addon(); // Introduced in 5.0.9
al_show_native_message_box( /* fill in params */ );
return 0;
}
You would need to link against the main Allegro library along with the native dialogs library.

Related

How to color output in C for cross-platform app

I am new and I know how to color output only in Unix/Linux systems:
#include <stdio.h>
int main(void) {
printf("\033[1;31mRed Message\033[0m.");
}
But this is not works in Windows cmd.exe, only in Unix terminal.
I am writing cross-platform app and want to know how can I do this in Windows cmd.exe too.
This also does not works:
1.
#include <stdio.h>
int main(void) {
printf("%c[1;31mRed Message%c[0m", 27, 27);
}
2.
#include <stdio.h>
int main(void) {
printf("[1;31m Red Message [0m");
}
This works, but I think this is just a bug:
If I type system(""); before printf then it works.
#include <stdio.h>
int main(void) {
system("");
printf("\033[1;31m Red Message \033[0m");
}
Thanks
If you want to make your library crossplatform, I would use the following approach:
Have a library, with the same functions, let's say:
void printInRed(const char* string). (In a headerfile)
After that you write two or more implementations.
One for windows:
//TODO: Errorchecking
void printInRed(const char* string){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
//TODO: Extract magic number
//See https://stackoverflow.com/a/4053879/13912132
SetConsoleTextAttribute(hConsole, 12);
puts(string);
}
And another one for unix-like OS:
//TODO: Errorchecking
void printInRed(const char* string){
printf("\033[1;31m%s\033[0m.", string);
}
Then you can check at compile time, which version to compile.
The first approach is to use #ifdefs, but this will make the code a bit messy.
Another approach would be to use a build-system like CMake to select at build time, which one to build. A buildsystem requires a bit of learning, but will help you to make maintaining a crossplatform library simpler.

Why does my code keep failing in codeblocks?

Here's the code I wrote.
#include <stdlib.h>
#include <stdio.h>
int main(void){
printf("hello World.");
return 0;
}
This is the error message
Execution of '"C:\Users\Happy Birthday\Desktop\Coding\C++\C_C++ project\simple program.exe"' in 'C:\Users\Happy Birthday\Desktop\Coding\C++\C_C++ project' failed.|
I figured it out. I had to go to the location of the bin for MinGW, copy and paste its address into the Toolchain executables tab of the global compiler settings, as opposed to auto detecting it.

Native C Code in Windows Phone Runtime

I am trying to use a existing c code in Windows Phone. For that I have created a Windows phone runtime component (C++) which has the legacy c code and referring it in my managed WP8 application.
I am facing issues in building the solution.
I have disable Precompiled headers option for "sample.c"
sample.h
int getNumber();
sample.c
#include <stdio.h>
#include"sample.h"
int main()
{
printf("This is a native C program.\n");
return 0;
}
int getNumber()
{
return 2014; // Sample value to return
}
NativeComponentRoot.cpp
#include "pch.h"
#include "NativeComponentRoot.h"
#include "sample.h"
using namespace NativeComponentRoot;
using namespace Platform;
WindowsPhoneRuntimeComponent::WindowsPhoneRuntimeComponent()
{
}
NumberGenerator::NumberGenerator()
{
}
int NumberGenerator::GetMeANumber()
{
int number = getNumber(); // Trying to invoke the function in sample.c
return number;
}
Issue
I couldnt find a proper walk through for integrating "C" (Not C++) lib/code in Windows Phone Runtime and using it in managed project.

new learner of c, the project is not compiled?

#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
system("PAUSE");
return 0;
}
After i Compiled the programme, i click run. it still tips me " project is not compiled" why? i am sorry, i am a new learner of c.
i am using dev c++, on xp, ctrl+F9 compile then ctrl+F10 run
it shows project is not compiled
multiple definition of main
Maybe in your project there is 2 Main function..
You should at least delete/change one..
if I see, there is 1-3.c and 1c.c
and the compile is error..
[Build Error]
CMIIW
Delete the file 1c.c. You cannot have two int main functions.

Compiling C program in NetBeans 7

I have a problem with netbeans 7 about debugging and running C program, the problem is that after I wrote the code as the following
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("done");
"khaled";
return 0;
}
in the output panel everything goes well but there's not any real output project (excutable file) no window appears.
I use gcc complier as the C compiler.

Resources