Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » learning allegro using a book, is this code flawed in the book or is it my comp

This thread is locked; no one can reply to it. rss feed Print
learning allegro using a book, is this code flawed in the book or is it my comp
ansimega
Member #7,984
November 2006

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

Thomas Fjellstrom
Member #476
June 2000
avatar

Add: #include <stdio.h> to the top of your file.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Richard Phipps
Member #1,632
November 2001
avatar

add:
#include <stdio.h>
underneath the other two #include lines.

EDIT: MOOOOOOSSSSEEEE!!!! >:(

LennyLen
Member #5,313
December 2004
avatar

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!

Johan Peitz
Member #9
April 2000
avatar

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.

--
johan peitz :: things I made

Thomas Fjellstrom
Member #476
June 2000
avatar

Ok, Wow. 4 messages at the same time.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

LennyLen
Member #5,313
December 2004
avatar

Who wants to play "Guess the book title?"

Richard Phipps
Member #1,632
November 2001
avatar

If the book example is going to use Allegro why not use rest() or readkey()?

LennyLen
Member #5,313
December 2004
avatar

Quote:

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...

ansimega
Member #7,984
November 2006

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.

Richard Phipps
Member #1,632
November 2001
avatar

Thomas Fjellstrom
Member #476
June 2000
avatar

He also claims to be a writer and a programmer.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

CGamesPlay
Member #2,559
July 2002
avatar

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!

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Evert
Member #794
November 2000
avatar

Quote:

is this code flawed in the book

If it's the book I think it is, then yes, it is.

EDIT

Quote:

the book is called Game Programming All In One

That's the one!

Quote:

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.

LennyLen
Member #5,313
December 2004
avatar

Evert said:

If it's the book I think it is

ansimega said:

the book is called Game Programming All In One by Jonathan S. Harbour

Edit: aha, I see you read back through the thread. ;)

Onewing
Member #6,152
August 2005
avatar

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...

------------
Solo-Games.org | My Tech Blog: The Digital Helm

LennyLen
Member #5,313
December 2004
avatar

Quote:

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.

Onewing
Member #6,152
August 2005
avatar

Apparently, he wrote this code first:

#include <conio.h>
#include <stdio.h>

int main()
{
  printf("Greetings Earthlings.\n");
  printf("All your base are belong to us!\n");
  getch();
}

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.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

LennyLen
Member #5,313
December 2004
avatar

Quote:

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.

Quote:

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. ;)

Thomas Fjellstrom
Member #476
June 2000
avatar

I think he assumed it was all money in his pocket, no matter what OS they used.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matthew Dalrymple
Member #7,922
October 2006
avatar

Thomas Fjellstrom said:

He also claims to be a writer and a programmer.

That made me laugh, big time :-D

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

Go to: