Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
传递给函数时,C类型从char*转换为int_C - Fatal编程技术网

传递给函数时,C类型从char*转换为int

传递给函数时,C类型从char*转换为int,c,C,我试图将文件名传递给线程函数,但它的类型在函数内部转换为int struct Data { char file_name; } void *Requestor(void *args) { struct Data *data = (struct Data*)args; printf("%s\n", data->file_name); //says expected char* but argument is type of int } int file_count

我试图将文件名传递给线程函数,但它的类型在函数内部转换为int

struct Data {
    char file_name;
}
void *Requestor(void *args) {
    struct Data *data = (struct Data*)args;
    printf("%s\n", data->file_name); //says expected char* but argument is type of int
}

int file_count = 5;
struct Data files[file_count];

for (int i = 0; i < file_count; i++) {
    printf("%s\n", argv[5 + i]); //this prints the file_name correctly;
    files[i].file_name = argv[5 + i]; // I get: warning: assignment makes integer from pointer without a cast [-Wint-conversion when compiling
    int thread = pthread_create(&(requesterThreads[i]), NULL, Requestor, &files[i]);
}
struct数据{
字符文件名;
}
void*请求者(void*args){
结构数据*数据=(结构数据*)参数;
printf(“%s\n”,data->file_name);//表示预期的字符*,但参数的类型为int
}
int file_count=5;
结构数据文件[文件计数];
对于(int i=0;i
您缺少一个
*
字符文件名;
应该是
char*文件名;
编译器警告您它是
int
而不是
char
的原因是
char
在varargs中使用时被隐式提升为
int

您缺少了
*
charile_name;
应该是
char*file_name;
编译器警告您它是
int
而不是
char
的原因是
char
在varargs中使用时隐式提升为
int