Код: Выделить всё
samiam@samiam-h-pc-2:~/projects/pascal/pascal-p6$ cat test.c
#include
#include
int main()
{
char buff[100];
getcwd(buff, 100);
printf("Current directory: %s\n", buff);
chdir("../libs");
getcwd(buff, 100);
printf("After set: Current directory: %s\n", buff);
}
samiam@samiam-h-pc-2:~/projects/pascal/pascal-p6$ gcc -o test test.c
samiam@samiam-h-pc-2:~/projects/pascal/pascal-p6$ ./test
Current directory: /home/samiam/projects/pascal/pascal-p6
After set: Current directory: /home/samiam/projects/pascal/pascal-p6
samiam@samiam-h-pc-2:~/projects/pascal/pascal-p6$ uname -a
Linux samiam-h-pc-2 5.15.0-139-generic #149~20.04.1-Ubuntu SMP Wed Apr 16 08:29:56 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
samiam@samiam-h-pc-2:~/projects/pascal/pascal-p6$ ls -d libs
libs
Может ли chdir() принимать относительные пути?
Подробнее здесь: https://stackoverflow.com/questions/797 ... tive-paths
Мобильная версия