Cheating Network
 
 

Go Back   Cheating Network > General Computing > Programming > Tutorials / Releases
Reload this Page [C] User input with variables



Tutorials / Releases

This is a discussion about [C] User input with variables 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, 04:40 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] User input with variables

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;
}
__________________
Want to donate to Cheating Network? Click here to do so, or just click the button below!


Chewy is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
input, user, variables


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Strings from Variables (PHP) ap0091 Programming 3 09-19-2008 08:55 PM
Pepsi Code Input Bot TheFalconer General Discussion of Networks/Survey Sites 13 05-27-2008 06:13 PM
Working on Tattoo Design (need input) TexasBabe Chit Chat 18 05-02-2008 01:58 PM
AHK Input question kad77 Programming 5 01-10-2008 10:40 PM


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