mardi 16 novembre 2021

How to fix expected 'const char *' but argument is of type 'char **` while using strcmp() in a function

It's supposed to be a function that finds the sum, difference etc of a two numbers depending on the chosen operator but when I use strcmp() to check the chosen operator I get the error expected 'const char *' but argument is of type 'char **'

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <string.h>

int calc(int ran1,int ran2,char op){
    if(strcmp(op, "+")==0){
        return ran1+ran2;
    }
    if(strcmp(op, "-")==0){
        return ran1-ran2;
    if(strcmp(op, "*")==0){
        return ran1*ran2;
    }
    if(strcmp(op, "/")==0){
        return ran1/ran2;
    }
    }
}
int main(){
    int ran1=25;
    int ran2=5;
    char op="+";
    printf("%d", calc(ran1, ran2, op));

}

Aucun commentaire:

Enregistrer un commentaire