#include <string>
#include <cstring>
#include <fstream>
#include <cstdio>
#include <cctype>
using namespace std;
static string fileName = "No File Name";
const char *fileNamePtr = 0;
int length = fileName.length();
char fileNameHolder = NULL;
string encryptThis(string &inFileName);
string decryptThis(string &newFileName);
string getFileName();
// Main function to request user input for file I/O
//*****************************************************************************
int main()
{
FILE *original;
FILE *copy;
FILE *read;
FILE *write;
original = fopen("UserFileName.txt", "r");
copy = fopen("UserFileName.txt", "w");
read = fopen("UserFileName.txt", "r");
write = fopen("UserFileNAme.txt", "w+");
while(fileNameHolder !=-1)
{
fileNameHolder = fgetc(original);
if(!isspace(fileNameHolder))
{
fputc(fileNameHolder,copy);
}
}
/*close open files*/
fclose(original);
fclose(copy);
fclose(read);
fclose(write);
printf("The copy operation has been complete");
fileNamePtr = fileName.data();
cout << "File Name Default is: " << fileName
<< "\nFile Name Default after c_str is applied is: "
<< fileName.c_str() << endl;
system("PAUSE");
system("CLS");
getFileName();
system ("PAUSE");
system ("CLS");
cout << "File Name Default is: " << fileName
<< "\nFile Name Default after c_str is applied is: "
<< fileName.c_str() << endl;
system("PAUSE");
system("CLS");
cout << "File Name after encryption\n" << encryptThis(fileName) << endl;
system("PAUSE");
system("CLS");
cout << "File Name after decryption\n" << decryptThis(fileName) << endl;
return 0;
}
// Main support functions
// Encrypt the user file name
// by adding one value to each string character
//================================================================
string encryptThis(string &inFileName)
{
fileName = inFileName;
for (int i=0; i<fileName.length(); i++)
{
++fileName[i];
}
return fileName;
}
//*****************************************************************************
// Decrypt the user file name
// for use in display
//*****************************************************************************
string decryptThis(string &newFileName)
{
fileName = newFileName;
for (int i=0; i<fileName.length(); i++)
{
--fileName[i];
}
return fileName;
}
//*****************************************************************************
// Prompt the user and get a string input,
// return fileName,
// used in Getter.
//*****************************************************************************
string getFileName()
{
cout << "Please enter the file name" << endl;
cin.ignore(cin.rdbuf()->in_avail());
cin >> fileName;
//cin.getline(fileNameHolder, _MAX_PATH);
//getline(cin, fileName);
return fileName;
}
/*
I am difficulty with the difference between strings and char.
How can I open a user defined file, write to the file, read from the file, close the file and delete the file.
I am pulling my hair out trying to figure this out...Any suggestions?
So far, I can entera string, encrypt it, decrypt is, and display it...I cannot however, create and file the string .txt file.
*/

New Topic/Question
Reply




MultiQuote



|