Teen Programmers Unite  
 

 

Return to forum top

communicating in command prompt

Posted by Faisal [send private reply] at June 19, 2002, 07:23:25 PM

How would it be possible to communicate using command prompt? How could a program be written to do that?

Posted by unknown_lamer [send private reply] at June 19, 2002, 08:00:16 PM

In C you want to look at sscanf and scanf as well as printf. For C++ use std::cout and std::cin. For Scheme (display) and (read) (or read-line if you are using the slib readline package OR Guile's (ice-9 rdelim) module).

Basic C++ (since that is what most people seem to use around here) command loop:

std::string command;
while (1)
{
std::cout << "prompt > ";
std::getline (std::cin, command);
process_line (command);
}

Just write process_line to tokenize the string and take actions based on them. Or you can use my game input parsing library at http://unknownlamer.org/code/game_parse.html (it isn't just for games really...you just give it commands to associate with tokens; you can do a lot with it).

Posted by Faisal [send private reply] at June 19, 2002, 09:08:22 PM

Chating with another user is what I meant. thanks anyway

Posted by Faisal [send private reply] at June 19, 2002, 09:08:51 PM

Or not nessesarily just chatting.

Posted by unknown_lamer [send private reply] at June 20, 2002, 08:11:05 AM

On GNU/Linux you can use write. 'write USER' will send a message to the user on the first terminal they logged in on. 'write USER ttyname' will send a message to user on ttyname. You type your message in write and hit ctrl-D to end. The other user can run write to talk to you too. You can keep running write between two users until you hit ctrl-D. You can probably grab the source from the GNU version of write to see how it works. You can also open() a terminal and write() to it if you have write permissions. You still have to figure out what terminal the user is on.

Posted by buzgub [send private reply] at June 20, 2002, 08:23:48 AM

Also assuming a unix, you could do freaky things with pipes to make the whole process of using write transparent (and hopefully more portable).

However, the problem as put by Faisal seems to be fundamentally ill-defined, and far too vague for me to actually be helpful. I'd suggest that sockets may be able to "solve" the "problem" here, in the same way that a blind man in a dark room suggests turning on the lights to help him see. More information may lead to a better answer.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.