20131019【C言語】remame関数を使う

お題

rename関数を使う

 

プログラム概要

myfile.txtをyourfile.txtにファイル名を変更する

 

ソース

#include <stdio.h>

 

int main(void)

{

if (rename("myfile.txt", "yourfile.txt"))

fprintf(stderr, "File copy error happend.\n");

else

fprintf(stderr, "Successfully copied!\n");

 

return 0;

}

 

実行結果

# ls -ltr myfile.txt yourfile.txt

ls: cannot access yourfile.txt: No such file or directory

-rw-rw-r-- 1 teru teru 0 Oct 19 07:58 myfile.txt

# ./a.out 

Successfully copied!

# ls -ltr myfile.txt yourfile.txt

ls: cannot access myfile.txt: No such file or directory

-rw-rw-r-- 1 teru teru 0 Oct 19 07:58 yourfile.txt