Originally Posted by
Daved
Give more details. A file usually only needs to see the declarations of functions it uses, but headers don't usually use functions, source files do. One exception is class declarations (for base classes or class members).
A file never has to see the definition of another function or class that it uses (except for templated code). Instead, you compile the definitions separately in separate source files and link them together at the end. Make sure all your cpp files are added to your project or makefile.
Like a .lib? Compile it how?
HEADER
Code:
#include <iostream>
#include <fstream>
void DisplayOptions();
void Overwrite(int Loops);
void Delete(std::string File);
int GetDiskSize(std::string Dir);
int GetFileSize(std::string File);
void CheckLength(std::string Dir);
std::string GetObject(std::string Object);
void MainFunction(std::string Dir,std::string File);
void RestartMainFunction(std::string Dir,std::string File);
void Choice(std::string Dir,bool Restart,std::string File);
void NoRestartMainFunction(std::string Dir,std::string File);
FUNCTIONS
Code:
Code in seperate source file
#include "..\Header\SecSuite.h"
#include <windows.h>
#include <iostream>
#include <fstream>
/*____________________________________________________________________________*/
void DisplayOptions()
{
std::cout<<"Welcome to C.J.'s Security 'suite'!\n";
std::cout<<"Please enter what you want to do.\n"<<std::endl;
std::cout<<"To select Secure Disk Wipe, input SDW.\n";
std::cout<<"To select Secure Disk Cleanse, input SDC.\n";
std::cout<<"To select Secure File Deletion, input SFD.\n";
std::cout<<"To select ---this option is not yet available---.\n";
std::cout<<"To select ---this option is not yet available---."<<std::endl;
std::cout<<"Option:";
}
/*____________________________________________________________________________*/
void Choice(std::string Dir,bool Restart, std::string File)
{
if (Restart=true)
{
RestartMainFunction(Dir,File);
}
if(Restart==false)
{
NoRestartMainFunction(Dir,File);
}
}
/*____________________________________________________________________________*/
void Delete(std::string File)
{
File="Del "+File;
system(File.c_str());
std::cout<<"File erased."<<std::endl;
}
/*____________________________________________________________________________*/
int GetDiskSize(std::string Dir)
{
__int64 i64FreeBytes;
typedef BOOL (WINAPI *PGETDISKFREESPACEEX)(LPCSTR,
PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);
PGETDISKFREESPACEEX pGetDiskFreeSpaceEx;
pGetDiskFreeSpaceEx=(PGETDISKFREESPACEEX)GetProcAddress(GetModuleHandle
("kernel32.dll"),
"GetFreeDiskSpaceExA");
GetDiskFreeSpaceExA(Dir.c_str(),
NULL,
NULL,
(PULARGE_INTEGER)&i64FreeBytes);
int SizeOfDisk=((i64FreeBytes/1024)/1024);
return SizeOfDisk;
}
/*____________________________________________________________________________*/
int GetFileSize(std::string File)
{
long end,begin;
int SizeOfFile;
std::ifstream a_File(File.c_str());
begin=a_File.tellg();
a_File.seekg(0,std::ios::end);
end=a_File.tellg();
a_File.close();
SizeOfFile=(end-begin);
return SizeOfFile;
}
/*____________________________________________________________________________*/
std::string GetObject(std::string Option)
{
std::string DirOrFileName;
std::cout<<"Please enter "<<Option;
getline(std::cin,DirOrFileName,'\n');
return DirOrFileName;
}
/*____________________________________________________________________________*/
void CheckLength(std::string Disk)
{
bool Loop;
while(Loop==true)
{
Disk="";
std::cout<<"Please try again:";
getline(std::cin,Disk,'\n');
if(Disk.length()==3)
{
Loop=false;
}
}
Loop=true;
}
/*____________________________________________________________________________*/
void MainFunction(std::string Dir,std::string File)
{
std::ofstream a_file(File.c_str());
int Loops=GetDiskSize(Dir);
while(Loops>0,Loops--)
{
a_file<<"1";
}
a_file.close();
std::cout<<"No space left on Drive"<<std::endl;
}
/*____________________________________________________________________________*/
void RestartMainFunction(std::string Dir,std::string File)
{
std::ofstream a_file(File.c_str(), std::ios::ate);
int Loops=GetDiskSize(Dir);
while(Loops>0,Loops--)
{
a_file<<"1";
}
a_file.close();
std::cout<<"No space left on Drive\n"<<std::endl;
}
/*____________________________________________________________________________*/
void NoRestartMainFunction(std::string Dir,std::string File)
{
std::ofstream a_file(File.c_str(), std::ios::trunc);
int Loops=GetDiskSize(Dir);
while(Loops>0,Loops--)
{
a_file<<"1";
}
a_file.close();
std::cout<<"No space left on Drive\n"<<std::endl;
}
/*____________________________________________________________________________*/
MAIN
Code:
#include "..\header\SecSuite.h"
int main()
{
std::string Dir,File,Option,Restart;
DisplayOptions();
getline(std::cin,Option,'\n');
if(Option=="SDW")
{
std::cout<<"Sorry,This option is not yet available."<<std::endl;
}
if(Option=="SDC")
{
std::string Dir=GetObject("DiskName");
if(Dir.length()!=3)
{
CheckLength(Dir);
}
File=Dir+"SecureDiskCleanse.txt";
bool FileExist=true;/*NEED TO WRITE THIS FUNCTION...*/
if(FileExist==true)
{
std::cout<<"Do you want to start where you left off?(Y or N):";
getline(std::cin,Restart,'\n');
if(Option=="Y"||"y")
{
RestartMainFunction(Dir,File);
}
else
{
NoRestartMainFunction(Dir,File);
}
}
else
{
MainFunction(Dir,File);
}
Delete(File);
std::cout<<"Disk Cleansed."<<std::endl;
std::cin.get();
}
if(Option=="SFD")
{
int Loops,SizeOfFile,OrigSizeOfFile;
File=GetObject("File location");
OrigSizeOfFile=GetFileSize(File.c_str());
std::ofstream a_file(File.c_str(), std::ios::trunc);
Loops=GetFileSize(File.c_str());
while(Loops>0,Loops--)
{
a_file<<"1";
}
Delete(File);
std::cin.get();
}
else
{
std::cin.get();
}
return 0;
}
Also, if any of you have any suggestions to improve my code, I'm all ears.