Go Back   Flash Flash Revolution > General Discussion > Technology
Register FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 09-4-2013, 08:30 PM   #1
MarioNintendo
Expect delays.
Retired StaffFFR Simfile AuthorFFR Music ProducerFFR Veteran
 
MarioNintendo's Avatar
 
Join Date: Mar 2008
Location: Montreal, QC
Age: 31
Posts: 4,121
Default Coding in C: help with if statements

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:

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");
	}
}
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 --------------------------------*/
	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");
	}
}
__________________
Click here to download my complete works!




Quote:
Originally Posted by macgravel View Post
Mario's files are top notch, so every time he submits a file I get excited in my pants.
Quote:
Originally Posted by hi19hi19 View Post
This guy, MarioNintendo?
Click the bricks


MarioNintendo is offline   Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 01:32 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution