我是C语言编码的新手。我想制作一个检测RobloxPlayerBeta.exe何时运行的程序,但编译时却说“传递'strcmp'的参数1使指针从整数开始而无需强制转换”。这是代码:
#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;
}
FindTask.exe是一个由以下python代码制成的exe:
with open(r"C:\Users\chall\Documents\Ccode\Logout\Tasks.txt","r") as db:
dataset = db.readlines()
for data in dataset:
if(data[:20].strip().lower() == "robloxplayerbeta.exe"):
with open("Tasks.txt","w") as f:
f.write("1")
我想知道什么是演员,为什么我需要一个演员。
强制转换是告诉系统将一种类型的数据转换为另一种类型的数据。
例子:
#include <stdio.h>
int main(void) {
int a = 10;
double b = (double)a; /* cast is used here */
printf("%f\n", b);
return 0;
}
在这种情况下,你不需要强制转换。strcmp()
用于比较字符串。你应该使用运算符处理数字以比较单个字符。
错误的:
thing = strcmp(value,"1");
正确的:
thing = value - '1';
thing = value - '1';
是不清楚的减法/比较。您喜欢@ chux-ReinstateMonica
thing = (value > '1' ? 1 : (value < '1' ? -1 : 0));
吗?解释减法的评论会有所帮助。或作为代码稍后使用
if (thing == 0){
,thing = value != '1';
就足够了。我认为@chux的意思是,你应该解释为什么你减去
1
从value
它分配给前thing
,什么该行代码呢,特别是作为OP似乎是相当新的语言。