my path is not detected when I'm trying to input a space in the directory.
Here is my code
#include<iostream>
#include <dirent.h >
using namespace std;
void directory_contents(char *directory_path)
{
DIR * dh;
struct dirent * contents;
dh = opendir(directory_path);
if (!dh)
{
cout << "The given directory is not found";
return;
}
while ((contents = readdir(dh)) != NULL)
{
string name = contents->d_name;
cout << name << endl;
}
closedir(dh);
}
int main()
{
int x, y;
char txt[1000];
cout << "Enter path:";
cin >> txt;
cout << "Text is " << txt;
directory_contents((char*) txt);
return 0;
}
I was thinking to use trim but I suppose there something I need to add to my code.I hope you can help me thanks!