LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2006, 10:25 PM   #1
tonyfreeman
Member
 
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196

Rep: Reputation: 30
Specifying Data Directory Locations in C Source


How does one substitute data directory information in C?

Here's the code:

Code:
// LOAD IN THE GAME BACKGROUND
temp = IMG_Load("data/images/background.png");
background = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
When I do the universal three step install:

Code:
./configure
make
sudo make install
... it installs my executable in /usr/local/bin and the images and other data files in /usr/local/share/Patolli

Patolli is the name of the project and executable.

Please help! What do I need to do to make sure the executable knows where the images are installed?

-- Tony
 
Old 02-07-2006, 04:00 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
try something like
Code:
static const std::string DEFAULT_IMAGE_PATH = "../share/Patolli/data/images/";

........

void load_image(std::string name)
{
   std::string full_path = DEFAULT_IMAGE_PATH + name;
   // LOAD IN THE GAME BACKGROUND
   temp = IMG_Load( full_path.c_str() );
   background = SDL_DisplayFormat(temp);
   SDL_FreeSurface(temp);
}
<edit> i see you using c not c++. in that case

Code:
static const char DEFAULT_IMAGE_PATH [] "../share/Patolli/data/images/";

........

void load_image(char* name)
{
   char full_path[50];
   strcpy (full_path,DEFAULT_IMAGE_PATH);
   strcat(full_path, name);

  // LOAD IN THE GAME BACKGROUND
   temp = IMG_Load( full_path );
   background = SDL_DisplayFormat(temp);
   SDL_FreeSurface(temp);
}
but this will only work on your machine, to work on others change the save path for the project and move the project there.

Last edited by dmail; 02-07-2006 at 05:50 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
No build directory in source directory FilthMasterFlex Mandriva 5 01-12-2005 03:03 PM
Kernel Source Tree locations? fintheman Linux - Software 1 09-29-2004 01:53 AM
where is linux source build directory/kernel source tree? webazoid Linux - Software 2 07-01-2004 08:37 PM
IMAP questions: file locations, directory appearance, mail appearance alake Linux - Enterprise 1 04-29-2004 04:24 PM
Question about source code locations hanzerik Linux From Scratch 4 02-06-2002 09:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration