LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-11-2010, 11:31 AM   #1
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
How to get variable values from the keyboard


I have been reading the Wikibook on C Programming for quite some time and am up to the variable part. I did learn several new things, like that too many variables hog memory.

What I want to know is how to assign a variable to the keyboard (in the C/C++ family) as such that the user has to type it in.
 
Old 07-11-2010, 11:38 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Kenny_Strawn View Post
I have been reading the Wikibook on C Programming for quite some time and am up to the variable part. I did learn several new things, like that too many variables hog memory.

What I want to know is how to assign a variable to the keyboard (in the C/C++ family) as such that the user has to type it in.
'man gets'

with mandatory after it

'man fgets'.

At all, learn about "Standard input/output", abbreviated to stdio. Specifically, about "standard input", abbreviated to 'stdin'.

And no, variable are not assigned to keyboard - you've got a wrong idea from somewhere.
 
Old 07-12-2010, 03:56 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by Kenny_Strawn View Post
like that too many variables hog memory.
All variables require memory, don't worry about too many variables. Rather consider if the variable is required and where it is required. Local variables will be created (use up memory) when they come into scope (often when the function is called) and the memory that they use will be released when they go out of scope (you return from the function).

Often additional variables can simplify the code by (for example) keeping track of the state or by recording intermediate results.

Quote:
Originally Posted by Kenny_Strawn View Post
What I want to know is how to assign a variable to the keyboard (in the C/C++ family) as such that the user has to type it in.
Others have given you some assistance here so I'll not add to it unless you require further help. However, if data is coming in from the keyboard you need to be careful and add error checking because the user my not enter what you expect, for example a user might type ten rather than 10.
 
  


Reply

Tags
keyboard, variables



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to invoke variable values vjayraghavan Programming 1 05-05-2010 02:22 AM
fork(), variable values between child and parent process???? dearvivekkumar Programming 6 02-24-2010 05:18 AM
Values like VARIABLE[i] ? BlueSpirit Programming 5 04-27-2007 01:35 PM
How to share variable values between shell and awk? realos Programming 1 12-16-2006 10:15 PM
bash - comparing a variable to several values davee Programming 3 05-05-2003 07:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration