c/c++ command to return pwd as char*

Discussion in 'OT Technology' started by BaZ, Sep 16, 2003.

  1. BaZ

    BaZ 2004 ACC Champions

    Joined:
    Jun 12, 2001
    Messages:
    2,005
    Likes Received:
    0
    Location:
    Hokieville, USA
    is there such a command to do so? my professor mentioned getenv(), but it doesnt seem to want to work for me.

    does anybody know?
     
  2. crotchfruit

    crotchfruit Guest

    hmm.. are you talking ANSI C, or can you use the Win32 API?

    here is one way off the top of my head:

    int main(int argc, char ** argv)
    {
    char* prog = argv[0];
    //prog is now, for example, "c:\myprogdir\myprog.exe"

    //do procedure to remove everything after last \
    //maybe strrchr is a good function to use?

    return 0;
    }
     
  3. BaZ

    BaZ 2004 ACC Champions

    Joined:
    Jun 12, 2001
    Messages:
    2,005
    Likes Received:
    0
    Location:
    Hokieville, USA
    heh obviously if i was looking for pwd then not Win32

    but yeah i found a function:

    char* get_current_dir_name(void) in unistd.h
     
  4. crotchfruit

    crotchfruit Guest

    true, but my solution is cross platform :naughty:
     

Share This Page