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

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

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

I am new to coding in the C language. I am trying to make a program that detects when the RobloxPlayerBeta.exe is being run, but upon compiling it says that "passing argument 1 of 'strcmp' makes pointer from integer without a cast". Here is the code:

#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 is an exe made with the following python code:

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

I would like to know what a cast is and why I need one.

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

Cast is to tell the system convert data of one type to another type.

Example:

#include <stdio.h>

int main(void) {
    int a = 10;
    double b = (double)a; /* cast is used here */
    printf("%f\n", b);
    return 0;
}

In this case you don't need cast. strcmp() is for compareing strings. You should use operators to deal with numbers to compare single character.

Wrong:

        thing = strcmp(value,"1");

Correct:

        thing = value - '1';