I am trying to traverse through a directory whose path is given but the following program is not going inside the directories and is stuck in infinit loop. What is the problem in this code:
void func(char path[]);
int main(int argc, char *argv)
{
    char buf[255];
    getcwd(buf,255);
    func(buf);
}
void func(char path[])
{
    DIR *dirp;
    struct stat states;
    struct dirent *direntp;
    dirp=opendir(path);
    chdir(path);
    while((direntp=readdir(dirp))!=NULL)
    {
        if(S_ISDIR(states.st_mode))//true than returns zero
        {
            printf("%s\n",direntp->d_name);
        }
    else
        if(!(strcmp(direntp->d_name,".")||strcmp(direntp->d_name,"..")))// if true retrns zero
        {   
            continue;
        }
        else
        {
            func(direntp->d_name);
            chdir("..");
        }
    }
}