Thread: How can I read the size of C:

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Question How can I read the size of C:

    How can I read the size of "C:\\"?

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    What in god's good name dost thou mean?

    1. C
    2. :
    3. \\
    4. \0

    4 bytes. Not to be confused with the sizeof the char* pointer that composes this string. That's how I read it. I don't know how you are reading things. Or where you are reading them from. Or in what context. You should probably elaborate, google, etc. on all these threads you are making because they're pretty vague really.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Okay, I admit that I was not clear enough, I am sorry.

    I meant the capacity of the partition C.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    If you're using Windows, then the call GetDiskFreeSpaceEx will help you. Might have to remove the Ex depending on which version of the OS you have. Look it up in MSDN for further help.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I have allready tried that but I gave up on it.

    http://cboard.cprogramming.com/showthread.php?t=69378

    Could you show me exactly how to do I want to do?

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    this worked for me. The code in the thread "converting LPDWORD to DWORD" is incorrect. GetDiskFreeSpace() parameters are pointer to your own objects -- whenever you see LPDWROD in Win32 API function parameters you must pass a pointer to your own object as shown below.
    Code:
    #include <windows.h>
    
    
    int main()
    {
    
      const char* lpRootPathName = "C:\\";
      DWORD SectorsPerCluster = 0;
      DWORD BytesPerSector = 0;
      DWORD NumberOfFreeClusters = 0;
      DWORD TotalNumberOfClusters = 0;
      GetDiskFreeSpace(lpRootPathName,&SectorsPerCluster,
    	  &BytesPerSector,&NumberOfFreeClusters,&TotalNumberOfClusters);
      char user[255];
      sprintf(user,"Sectors Per Cluster: %d\r\n",SectorsPerCluster);
      if(SectorsPerCluster > 0)
      MessageBox(0, user, "C:\\/%Details%/", MB_OK | MB_ICONINFORMATION);
    
      return 0;
    
    }
    Last edited by Ancient Dragon; 09-11-2005 at 04:01 PM.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well learning basic C++ would be a start.

    Your code
    Code:
      LPCTSTR lpRootPathName = "C:\\";
      LPDWORD lpSectorsPerCluster = 0;
      LPDWORD lpBytesPerSector = 0;
      LPDWORD lpNumberOfFreeClusters = 0;
      LPDWORD lpTotalNumberOfClusters = 0;
      GetDiskFreeSpace ( lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, 
        lpNumberOfFreeClusters, lpTotalNumberOfClusters);
      char* user;
      wsprintf(user,"Sectors Per Cluster: %d\r\n",dwSectorsPerCluster);
      if(dwSectorsPerCluster > 0)
      MessageBox(hwnd, user, "C:\\/%Details%/", MB_OK | MB_ICONINFORMATION);
    You pay no attention to the meaning of the parameters, you simply declare variables of the right type in the hopes that it will shut the compiler up. It takes more than that to write a program. You can't just create say a char * variable and then just use it because that's what the function says it wants.

    For example, any reading of the manual page would reveal that all those DWORD parameters were output parameters (that's where the answers would be stored).

    So it might be something like this
    Code:
      LPCTSTR lpRootPathName = "C:\\";
      DWORD SectorsPerCluster = 0;
      DWORD BytesPerSector = 0;
      DWORD NumberOfFreeClusters = 0;
      DWORD TotalNumberOfClusters = 0;
      GetDiskFreeSpace ( lpRootPathName, &SectorsPerCluster, &BytesPerSector, 
        &NumberOfFreeClusters, &TotalNumberOfClusters);
      char user[100];
      wsprintf(user,"Sectors Per Cluster: %lu\r\n",SectorsPerCluster);
      if(SectorsPerCluster > 0)
      MessageBox(hwnd, user, "C:\\/%Details%/", MB_OK | MB_ICONINFORMATION);
    > If the function fails, the return value is zero. To get extended error information, call GetLastError.
    Oh yeah, you need to do this as well, that's something else you can bone up on - handling errors.
    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
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Thanks.
    Oh yeah, you need to do this as well, that's something else you can bone up on - handling errors.
    Okay, where do I start?

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Okay, where do I start?
    By reading "If the function fails, the return value is zero. "
    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.

  10. #10
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I meant: bone up how?

  11. #11
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Cool-August
    I meant: bone up how?
    by reading MSDN documentation for the Wine32 api functions you want to use. see www.msdn.microsoft.com

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Start learning to read stuff for yourself - we're not going to spoon-feed you every single API function!!!!
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-04-2012, 07:36 AM
  2. Cannot read correct file size
    By coderplus in forum C Programming
    Replies: 7
    Last Post: 04-07-2012, 07:43 AM
  3. Valgrind - Invalid read of size 1
    By Castelmagno in forum C Programming
    Replies: 7
    Last Post: 02-29-2012, 03:19 PM
  4. Read Array Size
    By lonewolf367 in forum C Programming
    Replies: 4
    Last Post: 12-07-2005, 10:51 AM
  5. Getting size read with ifstream and read()
    By nickname_changed in forum C++ Programming
    Replies: 13
    Last Post: 08-03-2003, 06:05 AM