Skip to content

Instantly share code, notes, and snippets.

@sms420
Created July 2, 2009 05:33
Show Gist options
  • Select an option

  • Save sms420/139282 to your computer and use it in GitHub Desktop.

Select an option

Save sms420/139282 to your computer and use it in GitHub Desktop.
re-name-file-usr-input.cpp
//re-name-file-usr-input.cpp
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
ofstream button_E;
ofstream button_I;
button_E.open("_e.txt");
button_I.open("_i.txt");
string subject;
string string_used_to_rename_file;
cout << "subject number: ";
cin >> subject;
cin.ignore(80,'\n');
cout << "Word Up. It looks like you entered: ";
//FIRST copy for button e
char *e_new=new char[subject.size()+1];
// assign the value of zero to the array
e_new[subject.size()]=0;
// copy data from temp string into char array
memcpy(e_new,subject.c_str(),subject.size());
for (int i=0; i < 3; i++)
cout << e_new[i];
cout << endl;
e_new[3]='_';
e_new[4]='e';
e_new[5]='.';
e_new[6]='t';
e_new[7]='x';
e_new[8]='t';
char *e_old=new char[6];
e_old[0]='_';
e_old[1]='e';
e_old[2]='.';
e_old[3]='t';
e_old[4]='x';
e_old[5]='t';
rename(e_old , e_new);
//SECOND time - copy for i
char *i_new=new char[subject.size()+1];
// assign the value of zero to the array
i_new[subject.size()]=0;
// copy data from temp string into char array
memcpy(i_new,subject.c_str(),subject.size());
i_new[3]='_';
i_new[4]='i';
i_new[5]='.';
i_new[6]='t';
i_new[7]='x';
i_new[8]='t';
char *i_old=new char[6];
i_old[0]='_';
i_old[1]='i';
i_old[2]='.';
i_old[3]='t';
i_old[4]='x';
i_old[5]='t';
rename(i_old , i_new);
return 0;
}//closes program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment