Ok my Second C tut and some people asked me to Include some Variables with User input.
Lets Begin.
Create your main class and add the include stdio.h
Now we shall crate our variable. Lets call it Name and allow it to accept 1024 bytes
To do this we use the char* variable
The [1024] after name is optional and is called the buffer. It defines how many bytes of information the applicatoin can hold. This can cause problems with buffer overflow exploits
Now we need to have some user interaction. Lets make the application ask for the users name
Ok to allow the user to enter their name we use the scanf function
The scanf function should look like this
Notice our variable is mentioned there. this just tell the scanf function where to store the user input
Now we should make the application do a greeting. To make it greet simply print a message using the variable.
To print the variable we need to use %s and define what it is at the end. to do this add the following line.
Right thats your basic C application using Variables. This can be run in Linux, Windows, and Mac
The final code should be similar to bellow
If you wish to learn about Buffer Overflow : http://static.ihack.co.uk/affix/Discovery_of_Local_BoF_Exploits.pdf
Lets Begin.
Create your main class and add the include stdio.h
Code:
#include <stdio.h>
int main() {
}
Now we shall crate our variable. Lets call it Name and allow it to accept 1024 bytes
To do this we use the char* variable
Code:
char name[1024];
The [1024] after name is optional and is called the buffer. It defines how many bytes of information the applicatoin can hold. This can cause problems with buffer overflow exploits
Now we need to have some user interaction. Lets make the application ask for the users name
Code:
printf("Please enter your name!\n");
Ok to allow the user to enter their name we use the scanf function
The scanf function should look like this
Code:
scanf("%s", name);
Notice our variable is mentioned there. this just tell the scanf function where to store the user input
Now we should make the application do a greeting. To make it greet simply print a message using the variable.
To print the variable we need to use %s and define what it is at the end. to do this add the following line.
Code:
printf("Hello %s congradulations on your C Application\n", name);
Right thats your basic C application using Variables. This can be run in Linux, Windows, and Mac
The final code should be similar to bellow
Code:
#include <stdio.h>
int main() {
char name[1024];
printf(â€Please enter your name below!\nâ€);
scanf(â€%sâ€, name);
printf(â€Hello %s Congrats on the C app\nâ€, name);
return 0;
}
If you wish to learn about Buffer Overflow : http://static.ihack.co.uk/affix/Discovery_of_Local_BoF_Exploits.pdf


