use*_*779 1 c variables arguments opendir
我正在尝试这样做:
const char *p = "/home/paul";
dp = opendir(*p);
Run Code Online (Sandbox Code Playgroud)
但是失败并出现以下错误:
传递'opendir'的参数1使整数指针不带强制转换
我在这里不知所措,据我所知,我的尝试完全有效.毕竟,我将一个const char传递给一个函数,该函数的输入是一个const char.我究竟做错了什么?
该opendir()函数接受一个const char *参数,但你发送的是const char.*p 取消引用指向的值p,并返回数组中的第一个字符,即" /".所以结果*p是const char值" /".
p然而是一个const char *,所以改为:
dp = opendir(p);
Run Code Online (Sandbox Code Playgroud)