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

Username:   Password: 
 RegisterRegister   
 New Chat Program (with errors). Opening Files = Crash.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
templest




PostPosted: Fri Oct 22, 2004 4:31 pm   Post subject: New Chat Program (with errors). Opening Files = Crash.

I've been staring at this for thirty minutes trying to find out wtf is wrong with it. It opens the file perfectly the first time, gets and sets the username to what's in the "config.ini". But when I try to re-open the file in a process for changing the username, it gives me an "Invalid StreamNumber" error. Mad

Ideas?

code:
%juice-box
%v0.1
%by: templest d azmitia

import GUI
View.Set ("graphics:400;300,title:juice-box v0.1,nobuttonbar")
GUI.SetBackgroundColor (gray)

var input, output, font, font_bold, dummy_buffer, connection, file : int
var dummy_buffer_str, name : string

var port_list : array 1 .. 120 of int
font := Font.New ("verdana:8")
font_bold := Font.New ("verdana:8:bold")

dummy_buffer := 7200
for i : 1 .. 120
    port_list (i) := dummy_buffer
    dummy_buffer := dummy_buffer + 1
end for

name := "user"
proc getname
    open : file, "config.ini", get
    loop
        exit when eof (file)
        get : file, dummy_buffer_str : *
        if length (dummy_buffer_str) > 5 and dummy_buffer_str (1 .. 5) = "name:" then
            name := dummy_buffer_str (6 .. *)
        end if
    end loop
    close : file
end getname
getname

proc changename (new_name : string)
    dummy_buffer := 1

    open : file, "config.ini", put, mod, seek
    loop
        exit when eof (file)
        get : file, dummy_buffer_str : *
        if length (dummy_buffer_str) > 5 and dummy_buffer_str (1 .. 5) = "name:" then
            seek : file, (dummy_buffer)
            put : file, "name:" + new_name
            getname
            exit
        end if
        dummy_buffer := dummy_buffer + 1
    end loop

    close : file
end changename

connection := 0
proc connect (address : string)
    GUI.AddLine (output, "** Please wait while connecting... **")
    for r : 1 .. 120
        connection := Net.OpenConnection (address, port_list (r))
        if connection > 0 then
            exit
        end if
    end for

    if connection < 0 then
        %connection not established msg goes here
        GUI.AddLine (output, "** Connection to '" + address + "' failed **")
        GUI.AddLine (output, Error.LastMsg)
        GUI.AddLine (output, "")
    else
        %connection establish msg goes here
        GUI.AddLine (output, "** Connection to '" + address + "' has been established**")
    end if
end connect

proc input_string (msg : string)
    %processing of input goes in here
    if msg = "!quit" then
        GUI.Quit
    elsif length (msg) > 9 and msg (1 .. 8) = "!connect" then
        dummy_buffer_str := msg (10 .. *)
        connect (dummy_buffer_str)
    elsif length (msg) > 6 and msg (1 .. 5) = "!name" then
        dummy_buffer_str := msg (7 .. *)
        changename (dummy_buffer_str)
    else
        GUI.AddLine (output, name + " says: " + msg)
        if connection > 0 then
            put : connection, name + " says: " + msg
        end if
    end if
    GUI.SetText (input, "")
end input_string

input := GUI.CreateTextFieldFull (10, 10, maxx - 20, "", input_string, GUI.INDENT, font, 0)
output := GUI.CreateTextBoxFull (10, 35, maxx - 20, maxy - 45, GUI.INDENT, font)

loop
    exit when GUI.ProcessEvent
end loop
Sponsor
Sponsor
Sponsor
sponsor
templest




PostPosted: Fri Oct 22, 2004 6:49 pm   Post subject: (No subject)

Anyone? Crying or Very sad
Mazer




PostPosted: Fri Oct 22, 2004 7:54 pm   Post subject: (No subject)

I assume you mean when you type "!name xxxxx", right? Sorry, I can't find a problem with your code, I'm thinking turing is just... well, turing.
templest




PostPosted: Fri Oct 22, 2004 10:06 pm   Post subject: (No subject)

Coutsos wrote:
I assume you mean when you type "!name xxxxx", right? Sorry, I can't find a problem with your code, I'm thinking turing is just... well, turing.


Yes, and I'm begining to think: Yes. Goddamnit, I guess I'm going to start looking for some "C" PDFs in the very near future. I can't wait until second semester. Damn patience! In fact, damn it all! Damn it all to hell!
Tony




PostPosted: Fri Oct 22, 2004 10:23 pm   Post subject: (No subject)

Quote:

put : file, "name:" + new_name
getname <<-- ?
exit

well you call getname before closing the file, and are trying to open the same file from there
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
templest




PostPosted: Sat Oct 23, 2004 10:33 am   Post subject: (No subject)

Nope. I removed it from the procedure and added it afterwards, in the "if" statement that initializes the first changename.

code:

changename (dummy_buffer_str)
getname


Same thing happens.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: