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
Now we will create a variable called name the variable will be char.
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.
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
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
Now you have your fully functioning IF statment in C. Congradulations.
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
HTML:
#include
int main() {
}
Now we will create a variable called name the variable will be char.
HTML:
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.
HTML:
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
HTML:
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 statment in C. Congradulations.




