gpt4 book ai didi

c - 错误赋值从整数生成指针而不进行强制转换[默认启用]

转载 作者:太空宇宙 更新时间:2023-11-04 04:36:30 28 4
gpt4 key购买 nike

我对 C 编程还很陌生。我在编译我的程序时遇到了这个错误。我试图在互联网上寻找解决方案,但无济于事。错误在行 num = rand()%20;

char* getParameter(char *name)
{
char *num;

char *buffer;


if(strcmp(name,"Trainingsprogramm")){
srand (time(NULL));
num = rand()%20;;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"Personnenummer")){
srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"Tretzustand")){
srand (time(NULL));
srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"Tretleistung")){
srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"Drehzahl")){srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"Geschwindigkeit")){srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"GefahreneDistanz")){srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"RealeKJoule")){srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"AktuellerPuls")){srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"MomentanerGang")){srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"RelaxBetrieb")){srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}else if(strcmp(name,"VerbrauchteKJoule")){srand (time(NULL));
num = rand()%20;
sprintf(buffer,"%d",num);
}

return buffer;

}

最佳答案

尝试从 num 的声明中删除星号。

char *num; // <<< This is a pointer to char declaration
char num; // <<< This is a char

int num; // <<< But this is probably what you meant/wanted!

关于c - 错误赋值从整数生成指针而不进行强制转换[默认启用],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30141131/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com