aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework2/main.cpp
diff options
context:
space:
mode:
authorrPatrickWarner <[email protected]>2024-05-08 06:08:58 -0700
committerrPatrickWarner <[email protected]>2024-05-08 06:08:58 -0700
commitfb87b3d9bb8d028e8e16bfcaefdc8b27aeb2791d (patch)
treee7535e9602021b097051fac58767154b704ef193 /CST 126/Homework2/main.cpp
parentmore changes (diff)
downloadhomework-1-reecepwarner-fb87b3d9bb8d028e8e16bfcaefdc8b27aeb2791d.tar.xz
homework-1-reecepwarner-fb87b3d9bb8d028e8e16bfcaefdc8b27aeb2791d.zip
almost complete. decode and encode improvements
Diffstat (limited to 'CST 126/Homework2/main.cpp')
-rw-r--r--CST 126/Homework2/main.cpp112
1 files changed, 60 insertions, 52 deletions
diff --git a/CST 126/Homework2/main.cpp b/CST 126/Homework2/main.cpp
index 82a2d32..2f9d3d3 100644
--- a/CST 126/Homework2/main.cpp
+++ b/CST 126/Homework2/main.cpp
@@ -10,60 +10,69 @@ bool Worker(char** argv);
int main(const int argc, char* argv[])
{
- char* buffer = nullptr;
- char* MyEncodedCharArray = nullptr;
- bool success = false;
- const size_t size = SizeOfFile("randomtext.txt");
- buffer = new char[1];
-
- buffer = ReadFileAsBinary("randomtext.txt", buffer, size);
-
- MyEncodedCharArray = Base64Encode(buffer, size);
-
- success = WriteFileFromBinary(size, "destination_file.txt", buffer);
- delete[] buffer;
- //if (argc == ARG_COUNT)
- //{
- // Worker(argv);
- //}
- //else
- //{
- // //run other version!
- //}
-
-
-
+ if (argc == ARG_COUNT)
+ {
+ Worker(argv);
+ }
+ else
+ {
+ Worker();
+ }
- return Worker(); //can be used to trigger error controls
+ return 0;
}
bool Worker()
{
- char option = 'e';
-
- switch (option)
+ bool success = false;
+ char* MyEncodedCharArray = nullptr;
+ const char* MyFile = nullptr;
+ const char* Destination = nullptr;
+ char* buffer = nullptr;
+ size_t size = 0;
+ buffer = new char[size];
+ char Option = '\0';
+ do
{
- case 'e':
- //file reading binary
- //encoding
- //file writing text
- return true;
- case 'd':
- //file reading text
- //decoding work
- //file writing binary
- return true;
- default:
- std::cerr << "Error, invalid command option\n" <<
- "Valid commands:\n" <<
- "\t -e source_file.exe destination_file.exe" <<
- "\tEncodes file in source to text in destination txt file.\n\n" <<
- "\t-d source_file.text destination_file.exe" <<
- "\tDecodes text in source file into the destination file.\n\n";
- return false;
- }
+ Prompts("!Welcome to the Base64 Encoding/Decoding Menu!\n\ne)Base64 Encode Your File\nd)Decode Your Encoded File\nf)Exit\n\n");
+
+ std::cin >> Option;
+ switch (Option)
+ {
+ case 'e':
+
+ MyFile = InputFileName("What is the name of the file you wish to encode?: ");
+ Destination = InputFileName("\nWhat is the name of the file that you wish to save the encoded information?: ");
+ size = SizeOfFile(MyFile);
+ buffer = ReadFileAsBinary(MyFile, buffer, size);
+ success = WriteTextToFile(Destination, Base64Encode(buffer, size));
+ delete[] buffer;
+ return true;
+ case 'd':
+
+ MyFile = InputFileName("What is the name of the file you wish to decode?: ");
+ Destination = InputFileName("\nWhat is the name of the file you wish to save the decoded information?: ");
+ size = SizeOfFile(MyFile);
+ buffer = ReadTextFromFile(MyFile, buffer);
+ success = WriteFileFromBinary(size, Destination, Base64Decode(buffer, size));
+ delete[] buffer;
+ return true;
+ case'f':
+ std::cout << "Have a great day!" << std::endl;
+ break;
+ default:
+ std::cerr << "Error, invalid command option\n" <<
+ "Valid commands:\n" <<
+ "\t -e source_file.exe destination_file.exe" <<
+ "\tEncodes file in source to text in destination txt file.\n\n" <<
+ "\t-d source_file.text destination_file.exe" <<
+ "\tDecodes text in source file into the destination file.\n\n";
+ return false;
+ }
+ } while (Option != 'f');
+
return false;
}
@@ -82,22 +91,21 @@ bool Worker(char** argv)
switch (option)
{
case 'e':
- //filereading binary
buffer = new char[size];
-
+
buffer = ReadFileAsBinary(arg2, buffer, size);
MyEncodedCharArray = Base64Encode(buffer, size);
- success = WriteFileFromBinary(size, arg3, buffer);
+ success = WriteTextToFile(arg3, MyEncodedCharArray);
delete[] buffer;
return success;
case 'd':
- //file readingtext
- //decoding work
- //file writing binary
+ buffer = new char[size];
+ buffer = ReadTextFromFile(arg2, buffer);
+ success = WriteFileFromBinary(size, arg3, Base64Decode(buffer, size));
return true;
default:
std::cerr << "Error, invalid command option\n" <<