i have written small c language code to execute "dir" command which displays directories and files in the current directory, using system() function in c. But my code doesn't work. please help me.

# include <string.h>
# include <stdio.h>
# include <stdlib.h>
void main()
{
clrscr();
system("dir");
getch();
}

What is the problem that you are having with it?

i have written small c language code to execute "dir" command which displays directories and files in the current directory, using system() function in c. But my code doesn't work. please help me.

# include <string.h>
# include <stdio.h>
# include <stdlib.h>
void main()
{
clrscr();
system("dir");
getch();
}

You mean you wrote a 'batch' file using C, is dir a valid command for you operating sytem?

When running your program - what does it do...
1. does if fire off a run time error - if it does which one.
2. nothing - meaning the program executes but doesn't display the directory contents.

"my code doesn't work" may be fine for someone sitting beside you watching the process but we are located all over the world, please be provide details...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.