[Solved] folder name as variable

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

Moderators: cheriff, TyRaNiD

Post Reply
Pihas
Posts: 53
Joined: Sat Oct 25, 2008 10:26 pm
Location: Lithuania
Contact:

[Solved] folder name as variable

Post by Pihas »

How corectly to do it ? I can't find out :/
(C programing language + oslib)
----------------------------------------------

int folder_name_variable;

folder_name_variable = Brew;

Picture = oslLoadImageFile("Root/..folder_name_variable../test.png", OSL_IN_RAM, OSL_PF_5551);
Last edited by Pihas on Wed Jul 01, 2009 5:13 am, edited 2 times in total.
Image
Cooming Soon
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

Better learn to program C first...
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Producted
Posts: 56
Joined: Thu Jun 04, 2009 12:16 am

Post by Producted »

^That.
One of the first things you should learn is; what variables are and what they can do.

http://en.wikipedia.org/wiki/C_variable ... clarations
This might help.
Pihas
Posts: 53
Joined: Sat Oct 25, 2008 10:26 pm
Location: Lithuania
Contact:

Post by Pihas »

I am asking just to write one simple situacion and you bring me link to wiki and advise to learn C.... Is it so hard?...
Image
Cooming Soon
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

theres alot you need to learn but here

create a temporary collection or chars and use sprintf or snprintf look them up a good place is cpprefrence.com and cprogramming.com
svxs
Posts: 15
Joined: Fri Jun 19, 2009 10:03 am

Post by svxs »

int folder_name_variable;

folder_name_variable = Brew;

Picture = oslLoadImageFile("Root/..folder_name_variable../test.png", OSL_IN_RAM, OSL_PF_5551);
It's tough to see what you're trying to do. Is folder_name_variable really an integer, or should it be a string? What is the type of Brew?

The most confusing thing is whether or not you want the _name_ of the variable as a token in your string, or if you want the _contents_ of the variable in the string. In the former case, you're not going to be able to pull that off without some mightily obscure extension to your compiler unless you want to keep track of it somewhere else by yourself.

But even then, it doesn't make sense. How would you address the name of the variable? You'd logically need to know its name in advance anyway. I imagine the obscurity of it is a mitigating factor in ISO 9899's decision to not support that. :)

In the ladder case where you'd want the contents of the variable to show up in your string, you could use sprintf() to write a formatted string to a buffer and use that.
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

I think he's trying to do something like this:

Code: Select all

char* strfolder_path = "Brew";
/* No more than 80 characters in path */
char* strpath[80] = "Root/";

strcat(strpath, strfolder_path);
strcat(strpath, "/test.png");

Picture = oslLoadImageFile(strpath, OSL_IN_RAM, OSL_PF_5551);
Maybe... :/
Last edited by m0skit0 on Wed Jul 01, 2009 5:09 am, edited 1 time in total.
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Pihas
Posts: 53
Joined: Sat Oct 25, 2008 10:26 pm
Location: Lithuania
Contact:

Post by Pihas »

Thx m0skit0 that was exactly what i wanted to do . You saved my life time :-)

svxs, i am learnign programing by self and i don't know a lot things, even basics. I know other languages like PHP, LUA but have diferent sintax then C :/
Image
Cooming Soon
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You're making things harder on yourself by trying to learn both the PSP and C at the same time. We recommend people learn C, THEN move on to programming the PSP. It's easier, and means less basic questions here. We don't teach C, so if your question is C related, you're more likely to get razzed than to get an answer.
Post Reply