通过'的参数1;strcmp&x27;从不带强制转换的整数生成指针。什么是演员阵容?
我不熟悉用C语言编码。我试图制作一个程序来检测RobloxPlayerBeta.exe何时正在运行,但在编译时,它说“传递'strcmp'的参数1使指针从整数开始,而不进行强制转换”。 代码如下:通过'的参数1;strcmp&x27;从不带强制转换的整数生成指针。什么是演员阵容?,c,C,我不熟悉用C语言编码。我试图制作一个程序来检测RobloxPlayerBeta.exe何时正在运行,但在编译时,它说“传递'strcmp'的参数1使指针从整数开始,而不进行强制转换”。 代码如下: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> int logout(); char retrieve(); int main(){ c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int logout();
char retrieve();
int main(){
char value;
while(1){
system("cmd.exe /C tasklist > Tasks.txt");
value = retrieve();
printf("%d\n",value);
int thing;
thing = strcmp(value,"1");
printf("%d",thing);
if (thing == 0){
int x = logout();
}
sleep(10);
}
return 0;
}
int logout(){
system("c:\\windows\\system32\\shutdown /l");
return 0;
}
char retrieve(){
system("cmd.exe /C start C:\\Users\\chall\\Documents\\Ccode\\Logout\\dist\\FindTask\\FindTask.exe");
FILE *f;
f = fopen("Tasks.txt","r");
int number = fgetc(f);
return number;
}
我想知道什么是强制转换以及为什么需要强制转换。强制转换是告诉系统将一种类型的数据转换为另一种类型 例如:
#include <stdio.h>
int main(void) {
int a = 10;
double b = (double)a; /* cast is used here */
printf("%f\n", b);
return 0;
}
正确:
thing = value - '1';
strcmp
需要字符串参数,而不是单个char
。使用if(value=='1')
来比较字符。您不需要。你不应该在这里使用strcmp。但如果你连演员阵容都不知道,你需要从课堂、辅导等方面学到更多。;我们不能一次从头教你一个问题。为什么你声明retrieve
返回char
,但返回int number
?在检索
中也会泄漏文件句柄,因为使用后无法关闭文件。请参阅,这是否回答了您的问题<代码>事物=值-'1'“代码>是一个不清楚的减法/比较。@chux,你更喜欢东西=(值>1'?1:(值<1'?-1:0))代码>?解释减法的注释会有所帮助。或者作为以后使用的代码if(thing==0){
,thing=value!='1';
就足够了。我认为@chux的意思是,在将thing
赋值给thing
之前,你应该解释一下为什么要从value
中减去1
,以及这行代码的作用,特别是因为OP对语言来说似乎是相当陌生的。
thing = strcmp(value,"1");
thing = value - '1';