error in the program

shyma_nk
shyma_nk used Ask the Experts™
on
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>

void main(void)
{
  DIR *dirp;
  char strDirToScan[]="./testd2";
  int err;
  struct stat statinfo;
  struct dirent *direntp;
  dirp = opendir( strDirToScan );
  while ( (direntp = readdir( dirp )) != NULL )
  {
    err = stat(direntp->d_name, &statinfo);
    if (err == -1)
        exit(0);
  if(S_ISLNK(statinfo.st_mode))
      printf( "%s is a symbolic link\n", direntp->d_name );
    else
      printf( "%s is not a symbolic link\n", direntp->d_name );
  }
  closedir( dirp );
}

the stat function is returning only -1.can anyone tell me what may be the reason?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
whats the errorno?
try putting perror("Error :"), before exit if err if -1

err = stat(direntp->d_name, &statinfo);
   if (err == -1) {
      perror("Error\n");
       exit(0);
   }

this will print error message on screen(stderr)

-Rohan
Commented:
that's ok i solved the problem .it was an error dur to the path settings
Top Expert 2006

Commented:
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
PAQed/refunded

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Sunny
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial