C++ game programming compilers ...etc.

Started by
14 comments, last by MonkeyCookie 19 years, 4 months ago
i remeoved libiberty.h and it helped alot
only one error in this code:::
asprintf (&msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());

it says asprintf, undeclared in this function, how can i fix this, thanks anoynomous poster btw...
I'm 14,i design games,and I own CCGames,i have made about 15 games,mostly with Game Maker,PM me if you know how to create a level editor on GM :Pwww.coryandgrant.uni.cchttp://s4.invisionfree.com/ccgames_community JOIN!!!
Advertisement
I think you want sprintf, not asprintf.
Quote:
SYNOPSIS
#define _GNU_SOURCE
#include <stdio.h>

int asprintf(char **strp, const char *fmt, ...);

int vasprintf(char **strp, const char *fmt, va_list ap);
DESCRIPTION
The functions asprintf and vasprintf are analogues of sprintf and vsprintf, except that they allocate a string large enough to hold the output including the terminating NUL, and return a pointer to it via the first parameter. This pointer should be passed to free(3) to release the allocated storage when it is no longer needed.

NOTES
These functions are GNU extensions, not in C or POSIX. They are also available under *BSD. The FreeBSD implementation sets strp to NULL on error.


Probably a typo, anyway, since 'a' is next to 's' on a QWERTY keyboard. :)
okay, i did that and i got a few errors,
in the code were sprinf is:::


Quote:Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c sdl.cpp -o sdl.o -I"C:/Dev-Cpp/include/c++/3.3.1" -I"C:/Dev-Cpp/include/c++/3.3.1/mingw32" -I"C:/Dev-Cpp/include/c++/3.3.1/backward" -I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include" -I"C:/Dev-Cpp/include"

sdl.cpp: In function `int SDL_main(int, char**)':
sdl.cpp:92: error: cannot convert `char**' to `char*' for argument `1' to `int
sprintf(char*, const char*, ...)'

sdl.cpp:104: error: cannot convert `char**' to `char*' for argument `1' to `int
sprintf(char*, const char*, ...)'

make.exe: *** [sdl.o] Error 1

Execution terminated


-Thank you and it would be great if anyone could help me above :(
1. You define msg as a char* and pass the address of msg to sprintf (so it becomes a char**). Just remove the &.

2. If you ever come to this line you'll most certainly crash because msg is pointing anywhere into memory (you don't have memory reserved where the string can be written to). Either you allocate memory using new (don't forget to delete after usage) or you define msg not as a char* but as an char array (char msg[128] for instance).

regards Martin
Your best bet to start game programming isn't to just dive in but start with a book on C++. "C++ for Dummies" is actually a pretty decent book from what I've heard. Also I usually don't recommend starting with a lesser managed language (java, c#, etc.), but if you just wanna make a quick little game it may be best to look at those first.

At 14 it is hard to graps most of the computer languages, and more importantly being efficient at them is even more difficult.
The most important advice I have is to keep things simple. Starting on large complicated projects at first rarely leads anywhere. Start with a small, simple game and work up from there.

This topic is closed to new replies.

Advertisement