473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Hi im new to c++ and i need some help understanding

As above, i need to make a program out of c++ with encryption and file erasing function(prevents recovery) as my FYP. But the course never taught us c++ before so having alot of problems, hope that you can help.
Im incharged of the file erasure part and so im trying to understand this

Expand|Select|Wrap|Line Numbers
  1. bool WipeFile (string * inFilePath, int nWipes )
  2. {
  3.     bool status = false;
  4.     FileStream * sw;
  5.     Byte Patterns[];
  6.     __int64 fileLength=0;
  7.     int patIndex =0;
  8.  
  9.     if (nWipes<1) nWipes =1;
  10.     else if (nWipes>200) nWipes=200;
  11.  
  12.     try {
  13.         // Open the file with exclusive access
  14.  
  15.         sw = new FileStream (inFilePath, FileMode::Open ,
  16.                  FileAccess::Write, FileShare::None);
  17.  
  18.         Patterns = new Byte[nWipes] ;
  19.         // Create a pattern index
  20.  
  21.  
  22.         for (patIndex = 0; patIndex < 
  23.             Patterns->Count ; patIndex++) 
  24.             Patterns[patIndex] = patIndex;
  25.  
  26.         fileLength = sw->Length ;
  27.         for (patIndex=0; patIndex < 
  28.             Patterns->Count ; patIndex++) 
  29.         {
  30.             sw->Seek (0,SeekOrigin::Begin );
  31.             for (int i =0; i <= fileLength ;i++)
  32.                 sw->Write (Patterns,patIndex,1);
  33.           }
  34.         sw->Flush ();
  35.         sw->Close ();
  36.  
  37.         // Safe to remove the file now
  38.  
  39.         File::Delete (inFilePath); 
  40.         status = true;
  41.         }
  42.         catch (Exception * e) 
  43.         {
  44.             Console::Writeline (e->ToString());
  45.         }
  46.     return status;
  47. }
  48.  
btw i got this piece of code from codeproject.com
The thing is that it won't run which i suspect due to lack of include statements. What do i need inorder for this to work?
Sep 4 '08 #1
1 1064
Studlyami
464 Expert 256MB
Welcome to the bytes and THANK YOU for actually using the code tags. A bit of a warning this site considers the link you posted above as competition and they may remove the link/code. On the page where that code is located it was stated "The code is written for the .NET environment using Visual C++.NET". Is your project strictly using c++ or are you using .net as well? Also that code would "wipe out the contents of the file before it deletes it". Do you have to do this or can you just delete the file? If your just looking for a basic function to remove a file check out the remove function. You can see an example here. . Hopes this helps.

Also that code was just a function and not a complete executable program. Is this project going to be a console app or what GUI library are you using?
Sep 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
Hey guys, need some help understanding some things that maybe someone can explain or clarify it a little better then a text book. Here is my understanding so far: Class - basically a shell for...
3
by: Newbie | last post by:
I am extremely new to the working of XML. Our client wants us to access their Website. They also want us to retrieve XML (files?) from their site. We will then somehow import it into our SQL...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
1
by: Learner | last post by:
Hi there, I have designed a three tier arichitecture(presentation, business and datalayer). I have used Shared keyword in all my DL methods inorder to make them available in my BL. I have...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
0
by: Griff | last post by:
Hi folks, I need help understanding the reported thread counts on a system. We are running a .NET 2.0 service on a quad CPU box. The service programmatically sets a maximum of 300 worker and...
2
by: spenn | last post by:
I'm VERY new to VB and have an assignment that seems to jump from simple to complex in one leap. The assignment goes like this: access multiple files, search for a specific string, extract the...
0
by: Global Infotech Corporation | last post by:
Hi We have the following two positions open at one of our Client's site in the Silicon Valley, CA area. Our client, apart from being a pioneer in desktop publishing software provider, also makes...
1
by: SteveM | last post by:
I am writing a ToolUsage tracker which we will be accessing from each of our custom written tools. It will basically capture various pieces of information about the user, and the application they...
1
by: silverburgh.meryl | last post by:
Hi, I need some help in understanding the following for() loop: for (PRBool isRoot; mCSSUtils->IsRuleNodeRoot(ruleNode, &isRoot), !isRoot; mCSSUtils->GetRuleNodeParent(ruleNode, &ruleNode)) ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.