Posted by mm on July 27, 1999 at 17:52:24:
In Reply to: Easy Question posted by Vinnie on July 27, 1999 at 17:25:09:
: In the OutputDir function that was give to us ...
: void OutputDir ( char *dir, char level )
: {
: char s[2048];
: int state;
: DirectoryReader A (dir);
: while ((state = A.GetName (s, sizeof (s))))
: {
: if ((strcmp (s, ".") != 0) && (strcmp (s, "..") != 0))
: {
: for ( int i=0; i<=level; i++ )
: cout << "---";
: cout << s << "\n";
: if (state == 2)
: OutputDir (s, level+1);
: }
: }
: }
: How does the while statement work?
: while ((state = A.GetName (s, sizeof (s))))
: Wouldn't that *always* be true?
: I know I'm missing something simple ...
The return value from GetName is either 0 (for no more files), 1 (for a filename), or 2 (for a dir name). When GetName returns 0 (i.e., when there are no more directories or files), the while condition is false and the loop terminates.