gpt4 book ai didi

c - 警告 : implicit declaration of function 'strcmp'

转载 作者:行者123 更新时间:2023-11-30 19:01:26 26 4
gpt4 key购买 nike

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

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

关于c - 警告 : implicit declaration of function 'strcmp' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57830358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com