Warm tip: This article is reproduced from serverfault.com, please click
c

c-传递'strcmp'的参数1使指针从整数开始而无需强制转换。

(c - Passing argument 1 of 'strcmp' makes pointer from integer without a cast. What is a cast?)

发布于 2020-11-28 00:32:05

我是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")

我想知道什么是演员,为什么我需要一个演员。

Questioner
Confused_boy
Viewed
11
MikeCAT 2020-11-28 08:35:08

强制转换是告诉系统将一种类型的数据转换为另一种类型的数据。

例子:

#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';