Cheating Network
 
 

Go Back   Cheating Network > General Computing > Programming > Tutorials / Releases
Reload this Page [C] IF statement



Tutorials / Releases

This is a discussion about [C] IF statement within the Tutorials / Releases section, where you will Any tutorials or releases should be posted here.



Reply
 
LinkBack Thread Tools Display Modes
Old 04-09-2008, 05:01 AM   #1 (permalink)
CN Owner
 
Chewy's Avatar
 
Join Date: Dec 2007
Location: The deep end of CN
Posts: 2,512
Reputation: 61
Chewy will become famous soon enough
Send a message via AIM to Chewy
Default [C] IF statement

Like many other languages C has an if statement and it is pretty easy to grasp the concept. The if statement in C is very similar to the one you may have seen if you code PHP.

Ok lets start we will create a little application to ask for a name and compare it.

Start your C application by adding stdio.h and create your main function

Code:
#include <stdio.h>

int main() {


}
Now we will create a variable called name the variable will be char.

Code:
char name[1024];
Now we need to get the user to do some input by asking the name and receiving user input using the printf and sprintf functions. Your code should be similar to the followng.

Code:
printf("Hello, Please enter your name blow!\n");
scanf("%s", name);
Now say we want to check if a specific name is entered into the variable we need to use an if statement.

The if Statement looks like this

Code:
if(name == "Affix") {
    //ENTER THE TRUE FUNCTION
} else {
   //ENTER THE FALSE FUNCTION
}
The if statement above will check if Affix or iHack is entered as the name. Now if they are entered we will pass the TRUE function if the input it not valid we pass the FALSE function. I am simply going to display a message

Code:
if(name == "Affix") {
    printf("%s, You Fucking Rock\n", name);
} else {
   printf("%s, You Suck\n", name);
}
Now you have your fully functioning IF statement in C. Congratulations. Your code will look like the following.
__________________
Want to donate to Cheating Network? Click here to do so, or just click the button below!


Chewy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-09-2008, 08:37 AM   #2 (permalink)
Senior Member
 
krackhead's Avatar
 
Join Date: Dec 2007
Location: is this heaven?
Posts: 4,622
Reputation: 67
krackhead will become famous soon enough
Send a message via AIM to krackhead Send a message via MSN to krackhead
Default

i will try to learn it if i have time. thanks for helping keeping the site stay running.
__________________
Who says you can't trust a krackhead?
Seller Feedback
Buyer/Trader Feedback
krackhead is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
statement


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

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Powered by vBulletin
Copyright © 2000-2008 Jelsoft Enterprises Limited.
Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.