Im new to C và gặp sự cố khi sử dụng chdir(). Tôi sử dụng một chức năng để có được đầu vào người dùng sau đó tôi tạo một thư mục từ này và cố gắng để chdir() vào thư mục đó và tạo thêm hai tập tin. Khi tôi cố truy cập thư mục qua công cụ tìm (thủ công), tôi không có quyền. Dù sao ở đây là mã của tôi cho điều đó, bất kỳ lời khuyên?Thay đổi thư mục làm việc trong C?
int newdata(void){
//Declaring File Pointers
FILE*passwordFile;
FILE*usernameFile;
//Variables for
char accountType[MAX_LENGTH];
char username[MAX_LENGTH];
char password[MAX_LENGTH];
//Getting data
printf("\nAccount Type: ");
scanf("%s", accountType);
printf("\nUsername: ");
scanf("%s", username);
printf("\nPassword: ");
scanf("%s", password);
//Writing data to files and corresponding directories
umask(0022);
mkdir(accountType); //Makes directory for account
printf("%d\n", *accountType);
int chdir(char *accountType);
if (chdir == 0){
printf("Directory changed successfully.\n");
}else{
printf("Could not change directory.\n");
}
//Writing password to file
passwordFile = fopen("password.txt", "w+");
fputs(password, passwordFile);
printf("Password Saved \n");
fclose(passwordFile);
//Writing username to file
usernameFile = fopen("username.txt", "w+");
fputs(password, usernameFile);
printf("Password Saved \n");
fclose(usernameFile);
return 0;
}
Dòng này khá lạ: 'int chdir (char * accountType); ' – lbonn