Dev - C++ - Codigo del post anterior

   
Vista:

Codigo del post anterior

Publicado por Carlos (3 intervenciones) el 17/05/2010 13:57:15
Wenas tengo un codigo para un programa que monitorice el espacio libre de un disco duro pero tiene algunos errores asi que si alguien los pudiese revisar y mandarmelo arreglado se lo agradeceria.

Tiene comentarios en los lugares que falla.

#include <windows.h>
#include <winbase.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <stdio.h>

void fmtnumber(__int64 Number, char FmtNumber[]);
void fmtsize(__int64 Number, double &Size, char Units[3]);

void main()
{
BOOL success;
LPCTSTR DiskDirectory = "C:\\"; // directory name
__int64 AvailableBytes; // number of bytes on disk available to the caller
__int64 TotalBytes; // number of bytes on disk
__int64 FreeBytes; // free bytes on disk
DWORD SectorsPerCluster=0; // pointer to sectors per cluster
DWORD BytesPerSector=0; // pointer to bytes per sector
DWORD FreeClusters=0; // pointer to number of free clusters
DWORD TotalClusters=0; // pointer to total number of clusters

char FmtNumber[20];
double Size;
char Units[3];

success = GetDiskFreeSpaceEx(DiskDirectory, (PULARGE_INTEGER) &AvailableBytes,
(PULARGE_INTEGER) &TotalBytes, (PULARGE_INTEGER) &FreeBytes);
if (!success)
{
success = GetDiskFreeSpace(DiskDirectory, &SectorsPerCluster,
&BytesPerSector, &FreeClusters, &TotalClusters);
FreeBytes = FreeClusters * SectorsPerCluster * BytesPerSector;
TotalBytes = TotalClusters * SectorsPerCluster * BytesPerSector;
}

if (success)
{
cout.flags(ios::fixed);
cout << setprecision(2);
fmtnumber(TotalBytes - FreeBytes, FmtNumber);
fmtsize(TotalBytes - FreeBytes, Size, Units);
cout << "Used space: " << setw(15) << FmtNumber << " bytes";
cout << setw(8) << Size << setw(3) << Units << endl;

cout << setprecision(1);
fmtnumber(FreeBytes, FmtNumber);
fmtsize(FreeBytes, Size, Units);
cout << "Free space: " << setw(15) << FmtNumber << " bytes";
cout << setw(8) << Size << setw(3) << Units << endl;

fmtnumber(TotalBytes, FmtNumber);
fmtsize(TotalBytes, Size, Units);
cout << "Capacity: " << setw(15) << FmtNumber << " bytes";
cout << setw(8) << Size << setw(3) << Units << endl;
}
cout << Size << endl;
}

void fmtnumber(__int64 Number, char FmtNumber[])//1ra funcion
{
const int LBUF = 14;
const int LFMT = 17;

char buffer[LBUF], fmtbuffer[LFMT];
char _i64toa_s(Number, buffer, 10);//lo midifique agregando el char pero falta (Convierte un entero a una cadena)
int l = strlen(buffer) - 1;
int n=0;
int icount=0;
int i;
for(i=l;i>=0;i--)
{
if (icount==3)
{
fmtbuffer[n]=',';
icount=0;
n++;

}
fmtbuffer[n]=buffer[i];
icount++;
n++;
}
fmtbuffer[n]=0;
//strcpy(FmtNumber, strrev(fmtbuffer));//a modificar porke falta algo
}

void fmtsize( __int64 Number, double &Size, char Units[3])//2da funcion
{
const int KB = 1024;
const int MB = KB*KB;
const int GB = KB*MB;
double DIV;
if (Number>GB)
{
DIV = double(GB);
strcpy(Units,"GB");
}
else if (Number>MB)
{
DIV = double(MB);
strcpy(Units,"MB");
}
else
{
DIV = double(KB);
strcpy(Units,"KB");
}
Size = Number / DIV;
}

Gracias de antemano.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder