Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: implicit declaration of function 'strcmp' [duplicate]

Tags:

c

mingw

Creating a simple code that scans two numbers, asks the user if they would like to add or multiply them, and then performs the operation and prints the output.

#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;
}
like image 703
Jeremy Wolfe Avatar asked Apr 08 '26 20:04

Jeremy Wolfe


1 Answers

You are using strcmp function without declaring them. You need to include the header file which contains strcmp function declaration.

Use:

#include <string.h>
like image 69
Mohit Jain Avatar answered Apr 11 '26 13:04

Mohit Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!