How can I read the size of "C:\\"?
How can I read the size of "C:\\"?
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.
Okay, I admit that I was not clear enough, I am sorry.
I meant the capacity of the partition C.
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
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?
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.
Well learning basic C++ would be a start.
Your code
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.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);
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
> If the function fails, the return value is zero. To get extended error information, call GetLastError.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);
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.
Thanks.
Okay, where do I start?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?
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.
by reading MSDN documentation for the Wine32 api functions you want to use. see www.msdn.microsoft.comOriginally Posted by Cool-August
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.