- Back to Home »
- POINTERS IN C , SYSTEM PROGRAMS »
- chdir Example program in C, chdir Demo in C, program using chdir function in C
Posted by : ANIMESH SHAW
Monday, 6 February 2012
#include<stdio.h> #include<dos.h> #include<stdlib.h> #include<process.h>
const char * const path = "d:/popsys/test";
const char * const file = "lernc.txt";
int main () {
printf ("Changing directory to <%s>\n", path);
if (chdir (path) == -1) {
printf ("chdir failed - %s\n", strerror (errno));
}else {
printf ("chdir done !!!\n");
printf ("directory content of '%s'\n\n", path);
system ("ls -l");
printf ("\n");
printf ("checking the content of '%s'\n", file);
system ("cat lernc.txt");
}
return 0;
}

Post a Comment