警告:函数'strcmp&#39的隐式声明; [英] warning: implicit declaration of function 'strcmp'

查看:33
本文介绍了警告:函数'strcmp&#39的隐式声明;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

strcmp

您正在使用推荐答案函数,但未声明它们。您需要包括包含strcmp函数声明的头文件。

使用:

#include <string.h>

这篇关于警告:函数&#39;strcmp&#39的隐式声明;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆