aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework2
diff options
context:
space:
mode:
authorrPatrickWarner <[email protected]>2024-05-08 09:21:34 -0700
committerrPatrickWarner <[email protected]>2024-05-08 09:21:34 -0700
commit029f589f9a19a9eda2c4dffb319db96c7341e427 (patch)
tree2f80000bceb7745331434373b7749a58563739db /CST 126/Homework2
parentmore changes to encode/decode (diff)
downloadhomework-1-reecepwarner-029f589f9a19a9eda2c4dffb319db96c7341e427.tar.xz
homework-1-reecepwarner-029f589f9a19a9eda2c4dffb319db96c7341e427.zip
improvements to the binary writing function
Diffstat (limited to 'CST 126/Homework2')
-rw-r--r--CST 126/Homework2/Base64Helper.hpp23
-rw-r--r--CST 126/Homework2/Homework2.vcxproj1
-rw-r--r--CST 126/Homework2/Homework2.vcxproj.filters1
-rw-r--r--CST 126/Homework2/main.cpp4
-rw-r--r--CST 126/Homework2/newdestination.txt3
-rw-r--r--CST 126/Homework2/nextdest.txtbin128 -> 128 bytes
6 files changed, 15 insertions, 17 deletions
diff --git a/CST 126/Homework2/Base64Helper.hpp b/CST 126/Homework2/Base64Helper.hpp
index 744707f..20721bf 100644
--- a/CST 126/Homework2/Base64Helper.hpp
+++ b/CST 126/Homework2/Base64Helper.hpp
@@ -74,7 +74,7 @@ inline char* ReadFileAsBinary(const char* fileName, char* buffer, const size_t&
}
}
-inline bool WriteFileFromBinary(const size_t& size, const char* fileName, char* buffer, std::string fileContents)
+inline bool WriteFileFromBinary(const char* fileName, const char* buffer, std::string fileContents)
{
try
{
@@ -85,21 +85,14 @@ inline bool WriteFileFromBinary(const size_t& size, const char* fileName, char*
{
std::cerr << "Could not open file for binary output: " << fileName;
}
-
- size_t NewSize = fileContents.size();
-
- buffer = new char[NewSize];
-
- for (auto i = 0u; i < NewSize; i++)
- {
- buffer[i] = fileContents[i];
- }
-
- File.write(buffer, size);
+
+ buffer = nullptr;
+ buffer = fileContents.c_str();
+ size_t NewSize = fileContents.size() - 1;
+ File.write(buffer, NewSize);
File.close();
-
- return buffer;
+ return true;
}
catch (const std::exception& ex)
{
@@ -112,7 +105,7 @@ inline bool WriteFileFromBinary(const size_t& size, const char* fileName, char*
return false;
}
-inline bool WriteTextToFile(const char* fileName, std::string fileContents/*const char* fileContents*/)
+inline bool WriteTextToFile(const char* fileName, std::string fileContents)
{
std::ofstream File(fileName);
diff --git a/CST 126/Homework2/Homework2.vcxproj b/CST 126/Homework2/Homework2.vcxproj
index 188b85a..4b76c60 100644
--- a/CST 126/Homework2/Homework2.vcxproj
+++ b/CST 126/Homework2/Homework2.vcxproj
@@ -135,6 +135,7 @@
</ItemGroup>
<ItemGroup>
<Text Include="destination_file.txt" />
+ <Text Include="newdestination.txt" />
<Text Include="nextdest.txt" />
<Text Include="randomtext.txt" />
</ItemGroup>
diff --git a/CST 126/Homework2/Homework2.vcxproj.filters b/CST 126/Homework2/Homework2.vcxproj.filters
index 19a24ba..90c4068 100644
--- a/CST 126/Homework2/Homework2.vcxproj.filters
+++ b/CST 126/Homework2/Homework2.vcxproj.filters
@@ -31,6 +31,7 @@
<Text Include="destination_file.txt" />
<Text Include="randomtext.txt" />
<Text Include="nextdest.txt" />
+ <Text Include="newdestination.txt" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\..\..\Downloads\FindingPi.exe">
diff --git a/CST 126/Homework2/main.cpp b/CST 126/Homework2/main.cpp
index 2e246ff..1933eac 100644
--- a/CST 126/Homework2/main.cpp
+++ b/CST 126/Homework2/main.cpp
@@ -56,8 +56,8 @@ bool Worker()
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, buffer, Base64Decode(buffer, size));
- // delete[] buffer;
+ success = WriteFileFromBinary(Destination,buffer, Base64Decode(buffer, size));
+ //delete[] buffer;
return true;
case'f':
std::cout << "Have a great day!" << std::endl;
diff --git a/CST 126/Homework2/newdestination.txt b/CST 126/Homework2/newdestination.txt
new file mode 100644
index 0000000..1efd69c
--- /dev/null
+++ b/CST 126/Homework2/newdestination.txt
@@ -0,0 +1,3 @@
+text to test out binary file functions
+some more words and stuff
+some more words for testing! \ No newline at end of file
diff --git a/CST 126/Homework2/nextdest.txt b/CST 126/Homework2/nextdest.txt
index 6a29c3a..0be8381 100644
--- a/CST 126/Homework2/nextdest.txt
+++ b/CST 126/Homework2/nextdest.txt
Binary files differ