Hey peeps! Just started getting into C for University. I am experimenting with the language, and so far I came with a little problem. To begin with, here's my code:
What I'm trying to do is to make it "recognize" me. Sadly, even when I type Felix, it doesn't recognize me at all! It will always reply "I don't know you". I get no error from the compiler, so I assume this must be some kind of weird syntax mistake... What's going on here?
Weirdly enough, when I try to make a similar program using numbers this time around (integers, to be exact), it works like a charm. This is what makes me wonder why it doesn't work when I type letters. Here's an example:
Code:
#include <stdio.h>
int main (void)
{
/*Declarations --------------------------------*/
char yourname[30];
/*Program--------------------------------------*/
printf("What's your name, bro? ");
scanf("%s", yourname); // I ask the user to write his name
if (yourname == "Felix") // If the name entered is Felix, he gets a warm welcome.
{
printf("Hello master %s, king of the universe.\n", yourname);
}
else // If the name entered is anything other than Felix, the program doesn't recognize you.
{
printf("I don't know you\n");
}
}
Weirdly enough, when I try to make a similar program using numbers this time around (integers, to be exact), it works like a charm. This is what makes me wonder why it doesn't work when I type letters. Here's an example:
Code:
#include <stdio.h>
int main (void)
{
/*Declarations --------------------------------*/
int yourage;
/*Program--------------------------------------*/
printf("What's your age, bro? ");
scanf("%d", &yourage); // I ask the user to write his age, this time.
if (yourage == 20) // If the name entered is 20 years old, he gets a warm welcome.
{
printf("Hello my master, king of the universe.\n");
}
else // If the age is anything other than 20, the program doesn't recognize you.
{
printf("I don't know you\n");
}
}




Comment