How to change the working directory in C?

假装没事ソ 提交于 2019-12-13 06:25:52

问题


chdir can be used for constant character paths (it takes a const char *), but not for paths inputted by the user (since they have type char *). Is there any way around this?


回答1:


chdir can be used with arbitrary string. const modifier means that it will not modify your string.




回答2:


To expand on Roman Cheplyaka's answer, type qualifiers can always be added to pointer types, but not removed. This means that a function that takes a const char * parameter is really saying it can take either a char * or a const char * (which effectively means it is promising not to alter the contents of the string).

Similarly, a function that has a volatile char * parameter can take either a char * or a volatile char * as the actual argument, and a function that takes a const volatile char * parameter can take any of char *, const char *, volatile char *, or const volatile char *.



来源:https://stackoverflow.com/questions/3662627/how-to-change-the-working-directory-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!