GIDForums  

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

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Jan-2006, 10:54
alcoholic's Avatar
alcoholic alcoholic is offline
Member
 
Join Date: Nov 2005
Posts: 170
alcoholic is on a distinguished road

current drive number?


I would like to find current drive number...There was a function called getdisk() and setdisk() in <dir.h>...but it doesn't seem to work in new compilers...Is there any other function?
__________________
Gravitation is not responsible for people falling in love.
-Albert Einstein
  #2  
Old 05-Jan-2006, 11:07
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
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

Re: current drive number?


Quote:
Originally Posted by alcoholic
I would like to find current drive number...There was a function called getdisk() and setdisk() in <dir.h>...but it doesn't seem to work in new compilers...Is there any other function?

The C language and Standard C libraries (C++ also) are deliberately ignorant of file organization. Therefore, since functions about disk drives are necessarily implementation-dependent, you have to tell us: What operating system? What compiler? Maybe someone with the same setup as you can give you the information or a link to some reference.

Regards,

Dave
  #3  
Old 05-Jan-2006, 20:15
alcoholic's Avatar
alcoholic alcoholic is offline
Member
 
Join Date: Nov 2005
Posts: 170
alcoholic is on a distinguished road

Re: current drive number?


Windows 2000 Professional
Using both VC++6.0 & DEV C++ IDE
__________________
Gravitation is not responsible for people falling in love.
-Albert Einstein
  #4  
Old 06-Jan-2006, 07:30
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
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

Re: current drive number?


Quote:
Originally Posted by alcoholic
Windows 2000 Professional
Using both VC++6.0 & DEV C++ IDE

There is a function, getcwd(), that is present in some systems that retrieves the entire path to the current working directory. Since it is not a standard C library function, it is possible that not all systems have this function and for systems that have it, its prototype may not be in the same header file.

Compile the following program with VCC++6.0 (also works for Borland bcc32):

CPP / C++ / C Code:
#include <stdio.h>

/* For Microsoft and Borland compilers, uncomment
 * the <direct.h> statement and comment out
 * the <unistd.h>
 */
#include <direct.h>
/*#include <unistd.h> */
int main()
{
  char d[128];

  if (getcwd(d, sizeof(d))) {
    printf("from getcwd(): <%s>\n", d);
  }
  else {
    printf("getcwd() returned NULL\n");
  }
  return 0;
}

This also works with dev-c, but you might want to put the usual system("PAUSE") before the return 0; if you run it from the IDE. (and #include <stdlib.h> if you do this). Or use whatever you usually use to keep the window from closing upon termination (getchar() or whatever).

Cygwin gcc users don't have <direct.h>, but can find the prototype for getcwd() in <unistd.h> .

Note that getcwd() returns the entire path to the current working directory (the directory from which the program was invoked). Borland, Microsoft, and dev-c++ users can get the disk drive letter from the start of the path.

Regards,

Dave
  #5  
Old 06-Jan-2006, 07:55
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: current drive number?


Quote:
Originally Posted by davekw7x
... but you might want to put the usual system("PAUSE") before the return 0; ...
Dave!!! How could you?!?!?! I thought you knew better. See this.

By the way, alcoholic, have you checked MSDN? What you want is there and I believe it's a relatively obvious name.
__________________

Age is unimportant -- except in cheese
  #6  
Old 06-Jan-2006, 09:29
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: current drive number?


Walt, I guess Visual C++ automatically puts system("PAUSE") at the end of each program, so that "Press any key to continue.." appears.
What do you think? Well. I am not sure about this. Just a thought.

Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #7  
Old 06-Jan-2006, 10:36
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: current drive number?


Quote:
Originally Posted by Paramesh
Walt, I guess Visual C++ automatically puts system("PAUSE") at the end of each program, so that "Press any key to continue.." appears.
What do you think? Well. I am not sure about this. Just a thought.

Regards,
Paramesh.
Nope. In my experience, VC just lets the program flash on the screen so the user posts here to ask "why". I've heard DevC adds it, though -- which bothers me a lot!
__________________

Age is unimportant -- except in cheese
  #8  
Old 06-Jan-2006, 10:51
Levia Levia is offline
Junior Member
 
Join Date: Jan 2006
Posts: 65
Levia is on a distinguished road

Re: current drive number?


if you mean Dev-C++, not added there.
  #9  
Old 06-Jan-2006, 12:44
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
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

Re: current drive number?


Quote:
Originally Posted by WaltP
Dave!!! How could you?!?!?! I thought you knew better. See this.

By the way, alcoholic, have you checked MSDN? What you want is there and I believe it's a relatively obvious name.

Everybody is entitled to his/her opinion, and I respect yours and all of the other system("PAUSE") commandos. However, with dev-c++, (and, maybe, other IDEs as well), default console applications are built with system("PAUSE") just before the end of main() so that command line applications can be run from the IDE and the window will stay open until the user hits a key.

The system() function is a part of the C Standard Library and always has been. What happens when you invoke a program like "PAUSE" is obviously system-dependent (and won't work everywhere). If people aren't using dev-c++, and if their system doesn't have a "PAUSE" command, the system will complain at run time and the user can figure out what to do (or ask somebody). For beginners, I see no reason to make them do extra work to subvert the default behavior of their particular IDE just because of my opinion.

I, personally, never use system("PAUSE"). Note that nowhere in my program (or any other program that I have ever posted) to I use system("PAUSE"). On the other hand, I like to post things that work. If a user copied my program into a file in a dev-c++ project, it would work, but the window would close immediately (before the user had time to read the results). Then we would have got some inquiries concerning "how to keep the window open when running from the dev-c++ IDE". (Or, maybe, not. Anyhow, this way the answer is already there in case people actually read this stuff.)

On the other hand, checking with MSDN is guaranteed to give system-dependent functions (and lots of void main() examples that we all hate so much --- and it can be argued that void main() does violate C/C++ Standards). So: how can you excoriate a person for suggesting that it might be OK to use a standard library function in a way that is the default behavior for projects created by an IDE "wizard" (the Original Poster said that he was using dev-c++) while at the same time recommending a reference that has lots of useful information, but is pretty much guaranteed not to have standards-compliant solutions? (I use MSDN all of the time when looking for information about Windows programs and interfaces, which of course is systems-dependent by definition. I still shudder at all of the void main() examples.)

I would rather have beginners produce a program that executes according to their expectations and not be distracted by having people tell them about a lot of stylistic opinions that will not result in any improvement or fix any bugs in their programs. Style is important to me, as I have mentioned a few times (a lot of times, actually --- sometimes I get quite emotional about style), but insisting that others use my opinions as the basis for their programs is not where I'm at. Your Mileage May Vary.

Regards,

Dave

"A foolish consistency is the hobgoblin of little minds."
---Ralph Waldo Emerson
an essay on "Self-Reliance"
Last edited by davekw7x : 06-Jan-2006 at 13:54.
  #10  
Old 06-Jan-2006, 16:12
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: current drive number?


Quote:
Originally Posted by davekw7x
Everybody is entitled to his/her opinion, and I respect yours and all of the other system("PAUSE") commandos. However, with dev-c++, (and, maybe, other IDEs as well), default console applications are built with system("PAUSE") just before the end of main() so that command line applications can be run from the IDE and the window will stay open until the user hits a key.
I thought it was Dev-C....

Quote:
Originally Posted by davekw7x
The system() function is a part of the C Standard Library and always has been. What happens when you invoke a program like "PAUSE" is obviously system-dependent (and won't work everywhere). If people aren't using dev-c++, and if their system doesn't have a "PAUSE" command, the system will complain at run time and the user can figure out what to do (or ask somebody). For beginners, I see no reason to make them do extra work to subvert the default behavior of their particular IDE just because of my opinion.
But, "if their system doesn't have a "PAUSE" command ... the user can figure out what to do (or ask somebody)" why suggest something that may not work? Isn't there a command that ALL C/C++ users can use? rhetorical question

Quote:
Originally Posted by davekw7x
On the other hand, checking with MSDN is guaranteed to give system-dependent functions (and lots of void main() examples that we all hate so much --- and it can be argued that void main() does violate C/C++ Standards). So: how can you excoriate a person for suggesting that it might be OK to use a standard library function in a way that is the default behavior for projects created by an IDE "wizard" (the Original Poster said that he was using dev-c++) while at the same time recommending a reference that has lots of useful information, but is pretty much guaranteed not to have standards-compliant solutions? (I use MSDN all of the time when looking for information about Windows programs and interfaces, which of course is systems-dependent by definition. I still shudder at all of the void main() examples.)
The only time I recommend MSDN is when the user states they are writing for Windows (not another O/S) or when they've already stated they've been looking at it.
You shudder, I cringe.

Quote:
Originally Posted by davekw7x
I would rather have beginners produce a program that executes according to their expectations and not be distracted by having people tell them about a lot of stylistic opinions that will not result in any improvement or fix any bugs in their programs.
As would I, which is why I have a vendetta against system("pause"). It is NOT guaranteed to work. cin/getline(cin) and getchar()/fgets() will work with all C/C++ compilers on any operating system.

Quote:
Originally Posted by davekw7x
Style is important to me, as I have mentioned a few times (a lot of times, actually --- sometimes I get quite emotional about style), but insisting that others use my opinions as the basis for their programs is not where I'm at.
Style is important to me, and I personally find system("pause") to be extremely poor in style -- using an expensive O/S call when a simple input statement will accomplish the same thing.

My 2 dracmas... Well probably 4.

"Just because it can be done doesn't mean it should be done"
-- Barry Glasford (among others I'm sure)
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) 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
Binary number systems: BCD, twos complement, ones complement, etc. machinated Miscellaneous Programming Forum 6 08-Feb-2006 10:51
Knights Tour - Reloaded . kobi_hikri C Programming Language 12 03-Oct-2005 12:15
linked list error message Krandygrl00 C++ Forum 4 22-Jun-2005 14:13
Linked Lists DCOM C Programming Language 4 27-Mar-2005 00:00
Anyone can write a program code for this??? chriskan76 C Programming Language 1 19-Oct-2004 20:25

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

All times are GMT -6. The time now is 06:45.


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