LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-16-2007, 12:22 PM   #1
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Rep: Reputation: 30
Validating concatenated cin inputs (C++)


Hi guys,

I am trying to do a simple, CLi ftp client/server c++ application.

On the client end, once started, the command prompt will be:

ftp>>

just like a regular command line software.

At one point, I am suppose to let use key in the following to transfer file:

Quote:
put fileFromClient fileToServer
basically the above command will just copy a file from client to server.

I achieve that by issuing the following commands:

Code:
cin >> a >> b;
Where a and b are appropriate variables.

My question is, how can I validate the input, such that, if a user enters only 'put' or 'put fileFromClient' (basically not full commands which consist of the 3 arguements), I can capture it and prompt the user?

Right now, by concatenating cin, the software will keep waiting, such that if I type 'put', hit the return key, the application will appear to be waiting (for the next 2 input).

How can I capture the errornous user input from the moment the user hit the return key? and not let the program wait for the next 3 inputs from user, differentiate by the return key?

I tried using cin.good() but i think I am not getting it right...

anyone? thanks!

ps: this is for a school assignment, but I'm just asking about how can I validate concatenated inputs... not asking help for my work hehe - in case you're wondering

Last edited by Swakoo; 05-16-2007 at 12:23 PM.
 
Old 05-16-2007, 06:15 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You probably want to read the whole line, using the template method getine(), and then analyse the line for correctness.
 
Old 05-16-2007, 09:26 PM   #3
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
you mean cin.getline()?

I tried.. but that way I can't ensure i get 3 inputs on one line, without having the user enter it 3 times separately
 
Old 05-17-2007, 05:56 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
well that's why I said you need to check the line that has been read; that would basically mean split it up into tokens, broken down by spaces and see if there are three.
 
Old 05-17-2007, 09:03 PM   #5
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
so its not possible to prevent the user from pressing the 'return' key after keying in just 1 argument?

i was looking for possible ways to capture the user's action of entering, say:
Code:
put fileFromClient *hit return*
This way, the program will still wait for the 3rd argument.
 
Old 05-17-2007, 09:42 PM   #6
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Quote:
Originally Posted by Swakoo
so its not possible to prevent the user from pressing the 'return' key after keying in just 1 argument?
Not unless you intend to use ncurses or similar libraries.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
recover individual files concatenated with gzip dandini Linux - Software 7 09-04-2011 02:12 PM
Validating a user using C abdel Programming 2 07-19-2006 01:06 AM
Validating and Focussing In Java MRMadhav Programming 2 03-23-2006 09:02 PM
validating.... javier_ccs Programming 5 06-15-2005 08:22 AM
validating user input blanks Programming 3 09-02-2004 03:47 PM


All times are GMT -5. The time now is 04:57 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration