How to walk through folders?

Hi, I can't find a solution for a problem why "do{ ... } while(pabaiga!=pavadinimas);" isnt working? If "pavadinimas=-meniu" it does the same just like "pavadinimas!=-meniu", but I need it to go to int main when "pavadinimas=-meniu"...
And maybe you could help me with directories? It isnt working too. I want it to walk through folders. From one to other in all ways, not just one folder back pushing .. (dot dot), coming to the "home" folder pushing . (dot) and going to folder called "1" or "2" etc. I dont knowh why, but it cant open folder like "name", "folder" etc.
Please, I very need your help.
This is a code:

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
void narsyti5()
{
    const int dydis = 100; 
    std::string visi[dydis];
    int i = 0;
    char pavadinimas[255];
    char pabaiga[255]="-meniu";
    DIR *pdir;
    struct dirent *pent;
    
    for (i=0;i<256;i++)
    {
    pavadinimas[i]=0;
    }
    printf("Noredami pamatyti meniu rasykite: -meniu \n");//If you want to see menu, type: -meniu
    scanf("%s",pavadinimas);
    
do
{
    pdir=opendir(pavadinimas); 
if (!pdir)
{
    printf ("\nAtidarant direktorija ivyko klaida arba tokia direktorija neegzistuoja\n");
    system("PAUSE");
    exit(1);
  }//if
    errno=0;
    i = 0;
// Nuskaito direktorija ir paraso failus i visi[i]
while ((pent=readdir(pdir))!= NULL) 
{
 //visi[i] igauna failu pavadinimus
    visi[i] = std::string(pent->d_name);
    std::cout << " Failas " << i << ": " << visi[i] << std::endl;
    i++;
  }//while
if (errno)
{
    printf ("readdir() failure; terminating");
    exit(1);
  }//if
    scanf("%s",pavadinimas);
    std::cout << std::endl;
    closedir(pdir);
  } while(pabaiga!=pavadinimas);

  }//void 
Last edited on
You can't compare in this way
pabaiga!=pavadinimas
here is a simple function to compare arrays:
1
2
3
4
5
6
bool compare(char a[], char b[]){
for(long i=0;i<sizeof(a)/sizeof(char);i++){
if(a[i]!=b[i]) {return false;};
}
return true;
}

and
 
while(pabaiga!=pavadinimas); 

to
while(!compare(pabaiga,pavadinimas));
^LOL WUT? Ever heard of a little function called strcmp()?
Hey! Im a new guy, just trying to study C++, so do not abuse me for that...
I hope that will help me anyway...
Thank you very much for bouth compares. It works!
But how can I solve the other problem?
I need it to wlak through folders somehow.... :( Then it would be something like explorer for windows...
For directories:
http://linux.die.net/man/3/opendir

Good luck!
The problem is solved! Thank you very much,Packman,helios,Duoas!
Topic archived. No new replies allowed.