■要求定義
– ユーザ名の入力に合わせてカレントディレクトリを移動する
■検討事項
ディレクトリ一覧を取得し、ユーザ入力と一致したら移動か
#include <stdio.h>
#include <string.h> // 文字列操作
#include <unistd.h> // standard symbolic constants and types
int main(){
char pathname[512];
memset(pathname, '\0', 512); // memsetはバイトメモリブロックのセット
char path[64] = "./hoge";
chdir(path);
getcwd(pathname, 512); // getcwdはカレントディレクトリ
printf("%s\n",pathname);
return 0;
}
$ pwd
/home/vagrant/dev
$ ./dev
/home/vagrant/dev/hoge
cだと、chdir(path)でディレクトリを変更できる