Program

my this program is working when the argument is not provided why its not working when i m providing argument?

code :
#include<iostream>
#include <dirent.h>
using namespace std;
int main(int agrc ,char val[])
{
DIR
dir;
struct dirent * abcd;
if(!val[1])
{
/cout << "Invalid Execution Style: Use <Program Name> <Folder location>\n";/
dir = opendir(".");
if(dir !=NULL)
{
while ((abcd=readdir (dir))!=NULL)
{
if( abcd->d_name[0] != '.' )
printf ("[%s]\n", abcd->d_name);

                    \}
                    closedir\(dir\);

                    exit\(0\);
            \}
            dir = opendir\(val[1]\);
            if\(dir !=NULL\)
            \{
                    while \(\(abcd=readdir \(dir\)\)!=NULL\)
                    \{
                            if\( abcd-&gt;d_name[0] != '.' \)
                                    printf \("[%s]\\n", abcd-&gt;d_name\);
                    \}
                    closedir\(dir\);
                    return 0;
            \}
    \}

}

Note the line of text I marked in red in your posting above. My guess would be that you never get to the part where you try to read the directory named by the 1st operand. Try rebuilding and rerunning your code after removing that line.

i removed exit (0)...but its still the same

                dir = opendir(val[1]);
                if(dir !=NULL)
                {
                        while ((abcd=readdir (dir))!=NULL)
                        {
                                if( abcd->d_name[0] != '.' )
                                        printf ("[%s]\n", abcd->d_name);
                        }
                        closedir(dir);
                        return 0;
                } else {
                        printf("opendir(%s) failed\n", val[1]);
                        return 1;
                }
        }
}

So try adding the code in red above and see if it does anything.