Miscellany
public text v1 · immutablevoid change_dir(const char* path, ofstream& file, bool print)
{
char cwd[256];
if((string)path == "")
{
if(print)
file<<getcwd(cwd,sizeof(cwd))<<endl;
else
cout<<getcwd(cwd,sizeof(cwd))<<endl;
}
else if(chdir(path) != 0)
{
if(print)
file<<"ERROR: myshell: "<<path<<" does not exist"<<endl;
else
cout<<"ERROR: myshell: "<<path<<" does not exist"<<endl;
}
string temp = (string)getcwd(cwd,sizeof(cwd));
path = temp.c_str();
setenv("PWD",path,1);
}