April 24, 2013

Know Your Current Directory | Using C Programming

05:35 Posted by Unknown , No comments
The below program shows the usage of system() function to list down all the files and directories in the current directory:
#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



Post a comment

Please Enter your comment here......