Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Input and output at same time
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
echeese




PostPosted: Thu Jan 29, 2004 8:24 pm   Post subject: Input and output at same time

I'm trying to finish my chat program, and I need a way to get input without interrupting the chat's output. Can anyone give me an example of a way to put output to the screen and get input at the same time?

They must be able to watch the chat happen as they type.
Sponsor
Sponsor
Sponsor
sponsor
shorthair




PostPosted: Thu Jan 29, 2004 8:32 pm   Post subject: (No subject)

process , one word thats all
echeese




PostPosted: Thu Jan 29, 2004 8:40 pm   Post subject: (No subject)

That doesn't work Sad
Can anyone come up with an idea using getch?
shorthair




PostPosted: Thu Jan 29, 2004 8:42 pm   Post subject: (No subject)

it has to work , thats how i did mine , and mine works awsome , let me see some code so i can figure out why it wont work Very Happy Very Happy
Paul




PostPosted: Thu Jan 29, 2004 8:42 pm   Post subject: (No subject)

Im curious, how does getch help? doesn't it only take one character at a time? So, if you use it in a chat program and send one character at a time?
echeese




PostPosted: Thu Jan 29, 2004 8:43 pm   Post subject: (No subject)

code:
var debug : boolean := false
var irc, ran : int
var tmp, data, svrname : string := ""
var fnum : int
open : fnum, "file.dat", put
irc := Net.OpenConnection ("irc.avalonworks.ca", 6667)
put : irc, "USER echeese echeese echeese :echeese"
randint (ran, 1000, 9999)
put : irc, "NICK bot" + intstr (ran)

proc setcolor (col : int)
    if col = 0 then
        color (0)
    elsif col = 1 then
        color (7)
    elsif col = 2 then
        color (1)
    elsif col = 3 then
        color (2)
    elsif col = 4 then
        color (12)
    elsif col = 5 then
        color (4)
    elsif col = 6 then
        color (5)
    elsif col = 7 then
        color (6)
    elsif col = 8 then
        color (14)
    elsif col = 9 then
        color (10)
    elsif col = 11 then
        color (11)
    elsif col = 12 then
        color (9)
    elsif col = 13 then
        color (13)
    elsif col = 14 then
        color (15)
    elsif col = 15 then
        color (8)
    else
        color (7)
    end if
end setcolor

proc colorize (data : string)
    var j : int := 1
    loop
        exit when j = length (data) + 1
        if (ord (data (j)) = 3) then
            if j < length (data) then
                if (ord (data (j + 1)) > 47) and (ord (data (j + 1)) < 58) and (ord (data (j + 2)) > 47) and (ord (data (j + 2)) < 58) then
                    setcolor (strint (data (j + 1)) * 10 + (strint (data (j + 2))))
                    j += 3
                elsif (ord (data (j + 1)) > 47) and (ord (data (j + 1)) < 58) then
                    setcolor (strint (data (j + 1)))
                    j += 2
                else
                    color (7)
                    j += 1
                end if
            else
                j += 1
            end if
        else
            put data (j) ..
            j += 1
        end if
    end loop
    color (7)
end colorize

function getw (s : string, separator : char, n : int) : string
    var wi := 0
    var s2 := ""
    for i : 1 .. length (s)
        if wi >= n then
            if s (i) = separator then
                result s2
            end if
            s2 += s (i)
        end if
        if s (i) = separator then
            wi += 1
        end if
    end for
    if s2 not= "" then
        result s2
    else
        result ""
    end if
end getw

function getws (s : string, separator : char, n : int) : string
    var wi := 0
    var s2 := ""
    for i : 1 .. length (s)
        if wi >= n then
            s2 += s (i)
        end if
        if s (i) = separator then
            wi += 1
        end if
    end for
    if s2 not= "" then
        result s2
    else
        result ""
    end if
end getws

proc parse (data : string)
    if getw (data, " ", 0) = "PING" then
        put : irc, "PONG ", getws (data, " ", 1)
    elsif getw (data, " ", 1) = "MODE" then
        color (2)
        put "* ", getw (data, " ", 0) (2 .. *), " sets mode: ", getws (data, " ", 2)
        color (7)
    elsif getw (data, " ", 1) = "JOIN" then
        color (2)
        put "* ", getw (data, "!", 0) (2 .. *), " has joined ", getws (data, " ", 2) (2 .. *)
        color (7)
    elsif getw (data, " ", 1) = "NICK" then
        color (2)
        put "* ", getw (data, "!", 0) (2 .. *), " is now known as ", getws (data, " ", 2) (2 .. *)
        color (7)
    elsif getw (data, " ", 1) = "001" then
        put getws (data, " ", 3) (2 .. *)
        svrname := getw (data, " ", 0) (2 .. *)
    elsif getw (data, " ", 1) = "002" then
        put getws (data, " ", 3) (2 .. *)
    elsif getw (data, " ", 1) = "003" then
        put getws (data, " ", 3) (2 .. *)
    elsif getw (data, " ", 1) = "251" then
        put getws (data, " ", 3) (2 .. *)
    elsif getw (data, " ", 1) = "252" then
        put getw (data, " ", 3), " " ..
        put "IRC Ops online"
    elsif getw (data, " ", 1) = "254" then
        put getw (data, " ", 3), " " ..
        put "channels formed"
    elsif getw (data, " ", 1) = "255" then
        put getws (data, " ", 3) (2 .. *)
    elsif getw (data, " ", 1) = "265" then
        put getws (data, " ", 3) (2 .. *)
    elsif getw (data, " ", 1) = "266" then
        put getws (data, " ", 3) (2 .. *)
    elsif getw (data, " ", 1) = "372" then
        put getws (data, " ", 3) (2 .. *)
    elsif getw (data, " ", 1) = "375" then
        put "Message of the day"
    elsif getw (data, " ", 1) = "376" then
        put : irc, "JOIN #bots"
    elsif getw (data, " ", 1) = "PRIVMSG" then
        put "<", getw (data, "!", 0) (2 .. *), ":", getw (data, " ", 2), "> " ..
        tmp := getws (data, " ", 3) (2 .. *)
        colorize (tmp)
        put ""
    elsif getw (data, " ", 1) = "NOTICE" then
        color (4)
        put "-", getw (data, "!", 0) (2 .. *), "- " ..
        tmp := getws (data, " ", 3) (2 .. *)
        colorize (tmp)
        put ""
    else
        if debug = true then
            put data
        end if
    end if
end parse
put : irc, "JOIN #bots"
loop
    if Net.CharAvailable (irc) then
        loop
            get : irc, tmp : 1
            exit when ord (tmp) = 10
            if length (data) = 255 then
                exit
            else
                data += tmp
            end if
        end loop
        parse (data)
        data := ""
    end if
end loop
we64




PostPosted: Thu Jan 29, 2004 9:13 pm   Post subject: (No subject)

pretty complicated, I guess it is beyond my knowledge...
echeese




PostPosted: Fri Jan 30, 2004 10:28 am   Post subject: (No subject)

C'mon! Don't tell me it's IMPOSSIBLE! Can someone at least give me an idea?
Sponsor
Sponsor
Sponsor
sponsor
echeese




PostPosted: Fri Jan 30, 2004 10:49 am   Post subject: (No subject)

Well, I SORTA got it. I opened a new window for input. It's kinda cheap, but hey, it works. If anyone has a better idea, tell me.
sport




PostPosted: Fri Jan 30, 2004 3:38 pm   Post subject: (No subject)

Run the input in one process and output in the other. Process is the only solution and it works!!!
Cervantes




PostPosted: Fri Jan 30, 2004 3:57 pm   Post subject: (No subject)

process will do it...

um, just to make certain, you have to use the fork command when you use processes though.

Cheers
shorthair




PostPosted: Fri Jan 30, 2004 4:14 pm   Post subject: (No subject)

I said process right from the start , but he didnt want t ohear it , said it didnt work , but i know thats the way to do it
Cervantes




PostPosted: Fri Jan 30, 2004 5:34 pm   Post subject: (No subject)

yeah I know you said that, I was just stating the fact that I agree with you Smile
shorthair




PostPosted: Fri Jan 30, 2004 6:27 pm   Post subject: (No subject)

I wasnt countering Your Comment CErvantes ,sorry it loks like i did , hte comment was for echeese that said it shouldnt be that way , were all right about hte process ,even though they suck its tehe way to go , make a process then open up task manager , your cpu use is 100% always ( well on my apps may be different for someone else) ,
echeese




PostPosted: Fri Jan 30, 2004 6:53 pm   Post subject: (No subject)

Ok.. Listen, I used process and I was trying to type a message, and it ended up cut-up all over the place

eg

Hell[18:52] * Apage43 has left #oot
o everyb[18:52] <craig443:#oot> Hey guys
ody!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: