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?
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
chdir
can be used with arbitrary string.const
modifier means that it will not modify your string.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 achar *
or aconst 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 achar *
or avolatile char *
as the actual argument, and a function that takes aconst volatile char *
parameter can take any ofchar *
,const char *
,volatile char *
, orconst volatile char *
.