GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Jun-2005, 12:18
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

Current working directory.


How do I get the current working directory name ?

I read about getcwd but I can't use it. The compiler shouts that it can't open <unistd.h> .
I'm interested in an ansi-c function that will do the job.

Anyone ? Should I write my own function based on argv[0] ?

Kobi.
  #2  
Old 06-Jun-2005, 13:46
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by kobi_hikri
How do I get the current working directory name ?

I read about getcwd but I can't use it. The compiler shouts that it can't open <unistd.h> .
I'm interested in an ansi-c function that will do the job.

Anyone ? Should I write my own function based on argv[0] ?

Kobi.

There is no standard C (or C++) library function for getcwd --- it's operating system dependent. Here's what works for me with Borland bcc32 and Microsoft Visual C++. (For other, non-unix like, compilers, you can grep around in your include directory to see if there is something like getcwd().)

CPP / C++ / C Code:
#include <direct.h> /* For Borland bcc32 or MS VC++ 6 */
#include <stdio.h>

int main(int argc, char *argv[])
{
  char buffer[256];

  printf("argv[0]: <%s>\n", argv[0]);

  if (!getcwd(buffer, 256)) { /* returns null if path is too long */
    printf("Path name is too long\n");
  }
  else {
    printf("Current Working Directory is <%s>\n", buffer);
  }
  return 0;
}




Problem with argv[0]:

1. Not all compilers generate code that puts the entire path in argv[0] (in my case, Borland bcc32 does, but the Microsoft compilers give just the program name, not the path).

2. Even with the Borland compiler, argv[0] gives the path to the executable program, not the current working directory from which the program was invoked.


Regards,

Dave
  #3  
Old 06-Jun-2005, 16:07
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

Then I will write my own code :-)


Hey, Dave.
Thank's for your code and advice.
I will use your example and try to write my own generic function and post it.

Best regards,
Kobi.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Lists DCOM C Programming Language 4 27-Mar-2005 01:00
GIMcontacts - a gim fltk fluid venture cable_guy_67 FLTK Forum 0 14-Feb-2005 15:18
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 08:10
Apache2 config issues monev Apache Web Server Forum 2 28-Jun-2004 07:19
Can't view pages from another machine on the Intranet aevans Apache Web Server Forum 9 14-May-2004 03:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:49.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.