Thread: How to get the location of the program?

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    How to get the location of the program?

    How can I get the location of the program I'm running? Any function?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Location?
    Code:
    if ( isRunningOnEarth() ) {
      // examine earth rock
    } else {
      // examine mars rock
    }
    Boy, the questions sure have reached a new depth in vagueness.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    Is it where the program is saved or just the working directory?

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    12
    i didn't understand ur question.

    I assume this may be the answer for the question

    argv[0] parameter hold the fully qualified path name of the program ur running

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > argv[0] parameter hold the fully qualified path name of the program ur running
    Whilst it contains the program name (if available), there's no guarantee that it includes the whole path.
    What you get depends on what you type, and what your CLI does with it.
    Code:
    $ cat foo.c && gcc foo.c && ./a.out
    #include <stdio.h>
    int main ( int argc, char *argv[] ) {
        printf ( "%s\n", argv[0] );
        return 0;
    }
    ./a.out
    And its "your" not "ur"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    And its "your" not "ur"
    1.)What difference does it make?
    2.)Why should one require the full path if one intends on using it directly as some kind argument? So please specify what u want to use it for?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 1.)What difference does it make?
    http://www.catb.org/~esr/faqs/smart-...html#writewell
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Salem
    I agree in using proper English, but he was not the OP or the one asking the question. Your link is, "How To Ask Questions The Smart Way," not "How To Answer Questions The Smart Way."
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. Why does this program not work on my laptop?!
    By Eddie K in forum C Programming
    Replies: 1
    Last Post: 03-11-2006, 04:34 PM
  5. Replies: 5
    Last Post: 11-20-2003, 01:27 AM