learning allegro using a book, is this code flawed in the book or is it my comp
ansimega

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

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

Richard Phipps

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

EDIT: MOOOOOOSSSSEEEE!!!! >:(

LennyLen

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

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.

Thomas Fjellstrom

Ok, Wow. 4 messages at the same time.

LennyLen

Who wants to play "Guess the book title?"

Richard Phipps

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

LennyLen
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

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

okay. :)

Thomas Fjellstrom

He also claims to be a writer and a programmer.

CGamesPlay

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!

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

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

LennyLen
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

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.

LennyLen
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

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

Matthew Dalrymple
Thomas Fjellstrom said:

He also claims to be a writer and a programmer.

That made me laugh, big time :-D

Thread #588644. Printed from Allegro.cc