control chars past array
void createDir()
{
char* dirName = new char[8];
cout<<"Enter the name of the directory : ";
// doesn't work dirName[7] ='\0';
// doesn't work *(dirname + 7)='\0';
//
// I'm trying to get only 8 chars max. When anything over 7
//the program goes in to a continues loop. How can I discard
//all characters after 7 ?
cin.getline(dirName,8);
if(mkdir(dirName,777) < 0)
{
perror("Cannot create directory");
}
mkdir(dirName,777);
delete[] dirName;
}
Last edited by cxel91a; 08-14-2003 at 01:58 PM.
|