Problem with dirent.h

Hi everyone, I recently started working on a project that will look for a file, any file, and open it with its associated application (word for .doc, whatever the user uses for .mp3, etc). I'm using dirent.h to navigate through folders, and I was just testing it out and following tutorials when I found my first problem: The following code compiles, but it doesn't output anything to the console, even though I'm sure there are files and a folder in the same directory

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <dirent.h>

using std::cout;            using std::cin;
using std::endl;

int main(){
    DIR* dir_pter = NULL;
    struct dirent* ent_pter = NULL;

    dir_pter = opendir(".");

    if(dir_pter == NULL){
        cout << "ERROR: dir_pter failed to initialize." << endl;
        return 1;
    }

    while(ent_pter == readdir(dir_pter)){

        if(ent_pter == NULL){
            cout << "ERROR: ent_pter failed to initialize." << endl;
            return 1;
        }

        cout << ent_pter -> d_name << endl;

    }

    closedir(dir_pter);

    return 0;
}


Does anyone have any ideas? Thanks in advance
line 18: while(ent_pter == readdir(dir_pter)){ it compares ent_pter but never assigns it.

Are you sure that you know where ther current path "." is?
That was it, thanks for the quick answer, the while loop was supposed to test if readdir() was successful
Topic archived. No new replies allowed.