警告:函数“ strcmp”的隐式声明

时间:2019-09-07 03:07:24

标签: c mingw

创建一个简单的代码来扫描两个数字,询问用户是否要将它们相加或相乘,然后执行该操作并打印输出。

#include <stdio.h>
int main(){
int num1;
int num2;
char oper[] = "";
printf("Enter a number: ");
scanf("%d", &num1);
printf("Enter another number: ");
scanf("%d", &num2);
printf("Would you like to add or multiply these numbers? ");
scanf("%s", &oper);
if(strcmp(oper, "multiply") == 0){
    int prod = num1 * num2;
    printf("The product is %d", prod);
}
else if(strcmp(oper, "add") == 0){
    int sum = num1 + num2;
    printf("The sum is %d", sum);
}
else{
    printf("Why would you input something that you knew wouldn't work?");
}
return 0;
}

1 个答案:

答案 0 :(得分:1)

您正在使用strcmp函数而不声明它们。您需要包括包含strcmp函数声明的头文件。

使用:

#include <string.h>