Thread: Choosing the path of where to read/write

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    9

    Choosing the path of where to read/write

    Hi again.

    Finally, I'm done with my assignment... except for one thing !!
    It seems the specification sheet I got for the assignment didn't provide where.
    However, an example was given. Example is to use a server then two clients (as the server's argument). What happens here when I run two client examples, they write and read from where they are located.

    When it's about my program ( I used Visual C 2005 ), the read/write happens in the .../(projectname) file.

    Is there a way to make my program portable and let it read wherever it the (projectname).exe is located, or should it be specified ?

    my read example:
    Code:
    void main(int argc, char* argv[])
    {
    int i, t;
    	for (i=0 ; i<argc; i++)
    
    extractFileName(argv[0]);
    
    for (t=1; s->tank1Alive=="true" && s->tank2Alive=="true"; t++)
    {
    FILE *outfile, *infile;
    char buffer1 [30]; // for STATE file
    
    sprintf(buffer1, "p%dt%03d.state", i, t);
    infile = fopen (buffer1,"r");
    fscanf(infile, "%*s %d %d\n",&s->mapDimensionsX, &s->mapDimensionsY);
    }
    
    }
    Thanks for reading my problem

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    34
    I don't understand exactly what 's your question.
    Do you want to r/w a file in the same path where you executable is?
    If yes, you can use
    LPTSTR GetCommandLine(void);
    this function returns an unraveled argv[], with the exe's path in double-quotes in front.
    It works wor windows only.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    >>Is there a way to make my program portable and let it read wherever it the (projectname).exe is located

    It alreay is doing that. Just copy the program to some other folder and you will see it write in that new folder.

    BTW: There is no such compiler as "Visual C 2005" -- just being nitpicky

    >>void main
    Its int main(), never ever void The C and C++ standards require main() to always return an int. Anything else is non-standard and non-portable.
    Last edited by Ancient Dragon; 10-24-2010 at 06:54 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Implementation of path finder algorithm in C
    By user_name_void in forum C Programming
    Replies: 2
    Last Post: 11-23-2009, 12:31 AM
  3. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  4. Shortest path problem
    By Digitalxero in forum C++ Programming
    Replies: 0
    Last Post: 10-25-2005, 05:32 PM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM

Tags for this Thread