![]() |
|
#1
|
|||
|
|||
a C input questionHi, 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
|
|||
|
|||
Re: a C input questionQuote:
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:
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 GIDBlog
2nd Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
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