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 507 views
2 answers 283 views
1 answer 268 views
1 answer 263 views
1 answer 412 views
...