Some simple questions

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Some simple questions

Post by Ghoti »

Hi folks,

First of all i have a visual basic background so my C can be bad.
i have some problems getting my thingy to work. First off topic, my game always crashes after a certain frames. Why is this? i mean i had it some other time and then i looked like a variable i declared everytime the function was called took in all space. Is this right that every time i declare the same int i that it takes everytime some memory?

anyhow i have this problem with connection a directory name to a string. I tried alot but just won't work:

here is what i have tried:

Code: Select all

sprintf(buffer, "Themes/ dirEntry->d_name /Block1.png");
Blocks[1] = loadImage(buffer);

sprintf(buffer, "Themes/" + dirEntry->d_name + "/Block1.png");
Blocks[1] = loadImage(buffer);

sprintf(buffer, "Themes/" & dirEntry->d_name & "/Block1.png");
Blocks[1] = loadImage(buffer);
the dir-entry->d_name is a char variable so if someone can help me out here :)

the last question is something that has to do with displaying pictures. I use the png library and i use the graphics.h files distributed with the tutorial of Yeldarb. I load up the picture and displays them this works fine. However i want to change the picture so i try to free the memory and then reload it but everytime it freezes up.

P.S. is there something to debug psp software? like a windows prog that can run the program and shows where it halts (so i can see better what is the problem.)

greets ghoti
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

Try this:

Code: Select all

sprintf(buffer, "Themes/%s/Block1.png",  dirEntry->d_name); 
Blocks[1] = loadImage(buffer);
The sprintf() function takes a buffer and a format string, followed by zero or more other parameters. Every '%' in the format string tells sprintf() to replace that portion of the format string with the next parameter in sequence. In this case, "%s" tells sprintf() that a "string" should be formatted, so "%s" gets replaced with the directory name. The formatting works the same as for the printf() function.

Hope this helps!
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Here's more reference on the format string functions and how they work:

http://www.cplusplus.com/ref/cstdio/printf.html

It may look very complicated first, esp if you come from a language like basic, pascal (like I do) or java, but it's rather simple actually and is much mor flexible than the string concatenation of the other languages, once you get used to it. :)
Post Reply