Hi, i am learning to code with c& allegro, here is a script in the book it ask me to compile. I have already set the linker commands in my compiler "using dev c++"
This is code straight out of the book. I want to continue reading the book but i need to make sure my compiler is correctly set up.
#include <stdlib.h>
#include <allegro.h>
int main(){
allegro_init();
printf("Allegro version = %s\n", allegro_id);
printf("\n Press any key...\n");
system("pause");
allegro_exit();
return 0;
}
END_OF_MAIN()
errors
make.exe -f "C:\Documents and Settings\computer\Desktop\gameprogramming\ch2\Makefile.win" all
g++.exe -c GetInfo/getinfo.cpp -o GetInfo/getinfo.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -O3
GetInfo/getinfo.cpp: In function `int _mangled_main()':
GetInfo/getinfo.cpp:6: error: `printf' undeclared (first use this function)
GetInfo/getinfo.cpp:6: error: (Each undeclared identifier is reported only once for each function it appears in.)
make.exe: *** [GetInfo/getinfo.o] Error 1
Execution terminated
Add: #include <stdio.h> to the top of your file.
add:
#include <stdio.h>
underneath the other two #include lines.
EDIT: MOOOOOOSSSSEEEE!!!!
You need to add the following line at the start:
#include <stdio.h>
Edit: Darn, beaten by a blue friendly monster!
Edit2: And a moose!
I'm pretty sure you need to include stdio.h to get printf...
Also, system("pause") isn't very nice...
EDIT: Wow, for responses on the same minute.
Ok, Wow. 4 messages at the same time.
Who wants to play "Guess the book title?"
If the book example is going to use Allegro why not use rest() or readkey()?
If the book example is going to use Allegro why not use rest() or readkey()?
Well, if the author is silly enough to forget to include stdio.h...
Thanks guys, the book is called Game Programming All In One by Jonathan S. Harbour, he claimed he tested the code on every type of operating system.
okay.
He also claims to be a writer and a programmer.
By the way... I don't know if the book tells you to use C or C++, but that code will compile fine if you made it a "C" file instead of a "C++" file.
The "++" is for extra errors!
is this code flawed in the book
If it's the book I think it is, then yes, it is.
EDIT
the book is called Game Programming All In One
That's the one!
he claimed he tested the code on every type of operating system.
He blatently didn't. He also claimed "Allegro 4.2 is not backward compatible", which is false.
If it's the book I think it is
the book is called Game Programming All In One by Jonathan S. Harbour
Edit: aha, I see you read back through the thread.
In GPAIO edition 2, here's that same bit of code:
#include <conio.h> #include <stdlib.h> #include "allegro.h" int main() { allegro_init(); printf("Allegro version = %s\n", allegro_id); printf("\nPress any key...\n"); getch(); return 0; } END_OF_MAIN();
Just for reference...
In GPAIO edition 2, here's that same bit of code:
Which still won't compile since stio.h is again not included. Even if it were, conio.h functions are not part of the C standard.
Apparently, he wrote this code first:
And the next bit he adds the allegro stuff to that code. Somehow, stdio.h turned into stdlib.h for some reason. Also note in the first bit (the code I just posted), there's no return value at the end of main. 
Given, he didn't say this book was meant to be used for learning C nor did he mention it uses standard C.
Somehow, stdio.h turned into stdlib.h for some reason.
In the post by the OP, the book uses system(). This function resides in stdlib.h.
Given, he didn't say this book was meant to be used for learning C nor did he mention it uses standard C.
I guess he assumed all readers would be using DOS or Windows.
I think he assumed it was all money in his pocket, no matter what OS they used.
He also claims to be a writer and a programmer.
That made me laugh, big time :-D