Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 4th, 2005, 11:48 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to take input !!!!!

Hi, I am new with C# language. I got the book professional C# of wrox. I have read the 1st 6 or 7 chapters of this book and I found the book a good one but surprisingly now I find myself with a situation that I still don't know one thing and that is- in console mode how to take input from the keyboard. In these 7 chapters, there was not a single line about taking input values from the keyboard.I know about Console.ReadLine() but how to take input in 2 integer variables, I mean what is the scanf or cin equivalent of C#, plz help.

Goodluck and Goodbye...
 
Old January 4th, 2005, 06:13 PM
Kep Kep is offline
Authorized User
 
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think the way you get the same functionality as scanf is to use ReadLine and then use regular expressions to parse the information returned.

Or you could just use
Code:
int value1;
int value2;

Console.WriteLine("Enter value 1: ");
value1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value 2: ");
value2 = Convert.ToInt32(Console.ReadLine());
Kep.
 
Old January 6th, 2005, 11:02 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot for the reply, but what I actually need is to take few values that is in a single line

like this:

24 99 1002 33

i should have used: scanf("%d%d%d%d",&x,&y,&z,&p);

if I use ReadLine, then will it not destroy the whole line for just one value input.

I am trying to make a programme that can evaluate the value of an arithematic expression, so I need to take many values from a single line.

can you help me in this....thanks again.

Goodluck and Goodbye...
 
Old January 6th, 2005, 05:57 PM
Kep Kep is offline
Authorized User
 
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The ReadLine method returns a string so it is entirely possible to return your values...

24 99 1002 33

But you will have to split them up yourself using string.Split or regular expressions.


Kep.
 
Old January 7th, 2005, 11:34 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot, i think i can handle it from here, but i would have been happier if i had something like scanf which can automatically take those values from the stream, ok i will read about regular expressions and string.Split, thanks a lot...

Goodluck and Goodbye...





Similar Threads
Thread Thread Starter Forum Replies Last Post
No input file specified stephen_c_ Beginning PHP 3 January 27th, 2006 10:00 PM
Input type Mantis PHP How-To 9 December 10th, 2004 05:03 AM
How to input ID ? toms SQL Server DTS 2 August 6th, 2004 11:45 AM
validating input bukky VBScript 1 April 1st, 2004 04:30 AM
Input Panel matt.fields VB Components 3 November 13th, 2003 10:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.