GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Sep-2003, 01:04
tmike tmike is offline
New Member
 
Join Date: Sep 2003
Posts: 3
tmike is an unknown quantity at this point

a C input question


Hi, guys.....I have a question about keyboard input in C

I m writing a program...
which allows user to type command in the the prompt....then my program will do specified thing and so on

command are in the form: com parameter1 parameter2(or more)

for ex.
> move queue queue2

or
> add 12345 aibo queue2

the problem is, I don't know how to get those input...
because scanf can't get the whole string, it's space delimited....
also, since each of my command can have different # of parameters, this makes it more difficult, otherwise, I would have delcare a char* variable for each....

my question is is there any way to get the whole command in one string? then parse it?

or there's a better way to do it??

tks guys....
  #2  
Old 16-Sep-2003, 02:31
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough

Re: a C input question


Quote:
Originally posted by tmike
my question is is there any way to get the whole command in one string? then parse it?


Yes indeedy, there is. The function getline() will accept an entire line of input, stopping only at a carriage return. E.g.
CPP / C++ / C Code:
#include <iostream>
using namespace std;

int main(){
  string temp="";

  getline(cin, temp);  //get line from cin.
}

Now how do you parse it? You can scan along the string looking for whitespace. Or you can use some string functions, substr() and find(), to grab the arguments out of the string. Or you can use stringstreams.

I'll leave that to you

GF
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
a C input question.. tmike C Programming Language 2 19-Sep-2003 02:39
a noobish compiler question Charunks CPP / C++ Forum 5 03-Sep-2003 02:18
Script needed for letting user input a few days of data for tracking and analysis. tradertt MySQL / PHP Forum 3 06-Mar-2003 02:54
'Related articles' php /mysql question JdS MySQL / PHP Forum 4 06-Sep-2002 10:17
PHP Sessions question JdS MySQL / PHP Forum 2 16-Jul-2002 04:58

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:55.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.