How to change the current working directory to other directory in C

1 Answer

0 votes
#include <stdio.h>
#include <unistd.h>
   
int main(int argc, char **argv) 
{ 
    char curdir[255];
    char dir[32] = "d:\\test_dir";
    
    mkdir(dir);
    chdir(dir); // Change directory
    getcwd(curdir, 255);
    printf("Current directory: %s\n", curdir);
        
    return 0;
}
   
/*
  
run:
   
Current directory: d:\test_dir

*/

 



answered Sep 29, 2015 by avibootz

Related questions

2 answers 384 views
2 answers 139 views
1 answer 184 views
1 answer 178 views
1 answer 324 views
...