If I get rid of the function "int check(char inp)" and put its code in "main" the program runs fine. But when I try to make a separate function to check the input I get errors.
#include <stdio.h>
#include <string.h>
/*trying to create a function that handles the "strcmp" functions*/
int check(char inp)
{
/*int c in this function holds the return value*/
int c;
char option1[20] = "cute puppy";
char option2[20] = "good evening frank";
char option3[20] = "are those new shoes";
/*checks input against "option" variables for a match*/
if (strcmp(inp, option1) == 0)
{
c = 1;
}
else if (strcmp(inp, option2) == 0)
{
c = 2;
}
else if (strcmp(inp, option3) == 0)
{
c = 3;
}
return c;
}
int main(void)
{
/*variable that stores input*/
char inp[20];
printf("You begin by walking down the sidewalk just outside your house.\n"
"Its 11pm, nobody is out except your neighbor who is walking his dog.\n"
"What do you say as you walk past?\n\n"
"cute puppy - good evening frank - are those new shoes\n");
/*gets input from user and places it in "inp"*/
gets(inp);
/*if match is found int value is returned and assigned to "c" in "main"*/
int c = check(inp);
if (c == 1)
{
printf("works1\n");
return 0;
}
else if (c == 2)
{
printf("works2\n");
return 0;
}
else if (c == 3)
{
printf("works3\n");
return 0;
}
return 0;
}
play.c: In function 'check': play.c:11:14: warning: passing argument 1 of 'strcmp' makes pointer from integer without a cast [-Wint-conversion] if (strcmp(inp, option1) == 0)