如何使用Chdir()来更改我的工作目录 [英] how to use Chdir() to change my working directory
本文介绍了如何使用Chdir()来更改我的工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,我想更改我的工作目录我的代码中有什么问题,还是有其他方法可以更改目录?
< pre lang =cs> char str [ 200 ];
scanf( %80 [^ \\ nn],str) ;
(chdir(str)
解决方案
我也试试这件事给它分段错误
char str1 [ 400 ];
char str [ 200 ];
char dirc [ 200 ];
if (getcwd(dirc, sizeof (dirc))!= NULL){
scanf( %5 [^ \ r],str);
str1 [ 400 ] = sprintf( %s%s,dirc,str);
}
chdir(str1);
This is my code and i want to change my working directory what is the problem in my code or is there is any other way to change directory?
char str[200];
scanf("%80[^\r\n]", str);
(chdir(str)
解决方案
i also try this thing at it gives segmentation fault
char str1[400]; char str[200]; char dirc[200]; if(getcwd(dirc, sizeof(dirc)) != NULL){ scanf("%5[^\r]", str); str1[400] = sprintf("%s %s", dirc, str); } chdir(str1);
这篇关于如何使用Chdir()来更改我的工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文