The below program shows the usage of system() function to list down all the files and directories in the current directory:
#include<stdio.h>
#include<stdlib.h> //system( ) is included in this library
int main ()
{
int i;
printf ("\n");
i=system ("dir");// on windows
// i=system ("ls"); on linux or unix platforms
printf ("Returned value is: %d.\n",i);
return 0;
}
Another way
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char command[50];
strcpy( command, "dir" );//ls for unix machines
system(command);
return(0);
}
0 comments:
Post a Comment
Please Enter your comment here......