C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 17th, 2003, 10:48 AM
kfickert's Avatar
kfickert kfickert is offline
Capt'n
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2001
Posts: 541 kfickert User rank is Lance Corporal (50 - 100 Reputation Level)kfickert User rank is Lance Corporal (50 - 100 Reputation Level)kfickert User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 h 32 m
Reputation Power: 8
Do I need to set paths to files?

What I need to know is if in the following code I need to set a path to files, i.e. /path/to/users.dat.

I am a self taught programmer and mainly deal with PHP and CFML with MySQL and not C++.

This is designed for a unix based system and designed to compile using g++. It updates the backend to an online game and is run every X minutes via cron.

Here is the code:

#include <string>
#include <stdio.h>
#include <string.h>
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "Lupdate.h"
// WARNING: MAX structures[5] = 50000


Player::~Player()
{
delete []player_path;
delete []island;
delete []empire;
}
Player::Player(char *path)
{
char *new_path;
player_path = new char[strlen(path)+1];
new_path = new char[strlen(path)+6];

strcpy(player_path, path);
strcpy(new_path, path);
strcat(new_path, "/main");
strcpy(most_powerful, "/home/httpd/cgi-bin/most_powerful.dat");

island = new char[5];
empire = new char[5];

// load player, and if inactive, delete player
if(load_player(new_path))
{
delete_player(path);
}
delete []new_path;
}

bool Player::load_player(char *path)
{
ifstream fin;
string data_type;
int activity, data, slashes, j, k, i;

fin.open(path);
if(fin.fail()){ cerr << "Unable to open file " << path << endl; exit(1);}
//cout << "The file name is " << path << endl;
//cout << "Player Path is " << player_path << endl;

So every do I need to insert a /path/to/file.dat every time I see the word "path" or "*path"?

Thank you,
Kirk Fickert
__________________
Why? Because Forms just look cooler in OS X...

Dutch, it's like German...but not!

Last edited by kfickert : April 17th, 2003 at 10:54 AM.

Reply With Quote
  #2  
Old April 18th, 2003, 10:12 AM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
From my understanding of your problem, if the file is in the same directory as your program, you need not specify the path to it. If it is in a different directory, but is relative to the directory of your program, you could use something like "./datadirectory/files.dat", or "../data/file.dat". If it is in some arbitrary directory, then you need to specify the full path to it. I believe that this should be the path to which the user running the prorgam can see, and not the absolute path. For instance, if you need to access "/home/user1/datadir/file.dat", and user1 is running the prorgam, and he sees /home/user1 as the root, then you would need the program to access "/datadir/file.dat", since if you put "/home/user1/datadir/file.dat", the program would think that this is a directory off of user1's root, which is: "/home/user1/home/user1/datadir/file.dat". So, it depends on what the user can 'see' as root.

Reply With Quote
  #3  
Old April 18th, 2003, 10:26 AM
kfickert's Avatar
kfickert kfickert is offline
Capt'n
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2001
Posts: 541 kfickert User rank is Lance Corporal (50 - 100 Reputation Level)kfickert User rank is Lance Corporal (50 - 100 Reputation Level)kfickert User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 h 32 m
Reputation Power: 8
thanks, that helps to clarify things a bit.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Do I need to set paths to files?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway