Skip to content

Instantly share code, notes, and snippets.

@sms420
Created July 2, 2009 06:39
Show Gist options
  • Select an option

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

Select an option

Save sms420/139296 to your computer and use it in GitHub Desktop.
reanme a file from use iinput
//re-name-file-usr-input.cpp
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
int main()
{
ofstream button_E;
ofstream button_I;
button_E.open("e");
button_I.open("i");
string subject;
int result;
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[2];
e_old[0]='e';
button_E.close();
result=rename(e_old , e_new);
if (result ==0)
cout << "cool could renam e\n";
else
cout << "fuck, could not rename e\n";
//NEXT 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());
for (int i=0; i < 3; i++)
cout << i_new[i];
cout << endl;
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[2];
i_old[0]='i';
button_I.close();
result=rename(i_old , i_new);
if (result ==0)
cout << "cool, renamed i\n";
else
cout << "fuck, could not rename i\n";
return 0;
}//closes program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment