-2

I have a simple code that asks a user to input a folder for the program to work within.

    char MasterDirectory [50];
cout << "Please enter the directory containing the MP3 files you wish to have organised. " << endl;
cin >> MasterDirectory;

GetFileListing(MasterDirectory, "*.mp3");

However, the program doesn't function correctly if the input directory contains a space. Sorry for the rookie question, but how can I enclose the variable of "MasterDirectory" in quotation marks for GetFileListing?

RWest
  • 5
  • 2
  • whith std::string instead of a char array it wourld work (besides allocating only 50 characters is qwuite a "short" path) – okaerin Apr 10 '14 at 10:36
  • 50 was a throwaway number, something I wrote in haste for a test run. Also, apologies for the duplicate topic; can't believe I missed that. – RWest Apr 10 '14 at 11:12

3 Answers3

0

You must use cin.getline(MasterDirectory, 50);

Prabhu
  • 3,434
  • 8
  • 40
  • 48
0

Better use

cin.getline(MasterDirectory, sizeof(MasterDirectory));
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
0

You have to use std::getline to read full line with whitespaces;

can I enclose the variable of "MasterDirectory" in quotation marks?

Just add them to what you read (I suggest using std::string for flexibility):

std::string fileName;
std::cout << "Please enter the directory containing the 
              MP3 files you wish to have organised. " << endl;
std::getline( std::cin, fileName);
GetFileListing( "\"" + fileName + "\"", "*.mp3");

http://ideone.com/Lmi149

4pie0
  • 29,204
  • 9
  • 82
  • 118