Buffer solution???

Started by
5 comments, last by Noods 20 years, 8 months ago
I have a program that utilizes a set of tabs for different output windows (chat window, logs etc.) I have things pretty much set up as I want them, however, when I change tabs, I loose all the information within the child windows. How can I set up a buffer that can retain all this information, and still display it correctly (i.e. line breaks) when the respective tab is called again? I have tried using \n and \0 to no avail.
Advertisement
Unfortunately, you''re a little light on the detail in your explanation, so I can only answer it from a surface level. That is to say, you store that data exactly as you store any other data, in variables, arrays, etc. Assuming you mean Windows programming, just make sure that you manage events properly. If you get an event that says the user checked a check box, for instance, update a variable that says that box is checked. If you have an event that says the user''s typing in an edit box, update a string that stores its contents. Sorry, that''s about as much as I can say with the detail you''ve given.

-Arek the Absolute
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
Sorry for the light detail, let me elaborate.

I have a fully functional chat server and client programmed. Communication is fully functional both ways. On the server, I have several tabs. One is to view logs, one is the main chat screen. When people communicate with each other, the child windows for input and output update properly. (clear input, scroll up, new line - just like any normal chat program) However, when I change to the "Logs" tab, and change back to the "Chat" tab, all my chat information is gone. This is because I was basically letting windows worry about the child window information, and there is no specified space within the program that I am saving the information.

I am assuming I can use a character buffer to save this information, but I am going to need to save it in a certain format. (due to the text being on different lines) I dont know how to do this. Thanks for any help you can offer.
I don''t understand why you''d need to save it in a special format just because it''s on multiple lines. Assuming the text is in an edit box, it''s very easy to read in all the text. Even if it''s not in an edit box, it''s just a matter of properly updating a string whenever you get a certain event that indicates new input. Then, when you have everything in a buffer, you can very easily stick it in a file, something like this:

FILE *pfile = fopen("log.txt","w");

for (int loop = 0; loop < strlen(buffer); loop++)
putc(buffer[loop],pfile);

fclose(pfile);

Well, I''m probably still not helping. As far as I understand, all you need to do is store a buffer, and then simply update the child''s text when it needs it. That same buffer can be used to save it whether it has multiple lines or not. Oh well. I''m more than likely going to just shut up on this thread after this, just because I''m betting it''s my own fault i''m not understanding you, not the other way around.

-Arek the Absolute
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
Let me simplify.

Chat:

User 1: Hey Jim whats up?
User 2: Hey Tom nothing much, how about you?
User 1: Im ok.

Here is where I save the file:

MiscTextSaveFunction(blah blah blah);

Here is my saved text file "User 1:Hey Jim whats up?User 2: Hey Tim nothing much, how about you?User 1: Im ok."

Here is my output:

User 1:Hey Jim whats up?User 2: Hey Tim nothing much, how about you?User 1: Im ok.

See how my characters are just a jumble of crap? I need a method of formating this so I can output the characters in a manor that looks like a normal chat. (i.e. either sticking something something to indicate a newline in the text string, or a way to specify each line individually.
There are a few areas that could be occurring. It could be that in whatever you read in from the chat, that you''re not reading in the endline character. If that''s the case, I''ll assume for the moment that it works like this:

User 1 types in and enters: "Hi there, how''s it going?"
your server receives: "Hi there, how''s it going?"
when it should have "Hi there, how''s it going?\n"
In which case, you can simply add in a newline at the end of every message you recieve.

If that''s not the case, I''d remind you that for some means of display just a \n won''t go to a new line, and you instead need \r\r\n. (telnet''s like this, if i remember rightly) Maybe it''s just that problem in displaying. In that case, I''d say the best thing to do would be to make one pass through your buffer and count how many \n characters you have. Then create a new buffer that''s the same length, plus whatever amount you need to add for \r''s. Then in a for loop simply copy over everything bit by bit. When you find a \n, add the \r''s first.

After this, I quit. Sorry for wasting your time.

-Arek the Absolute
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
Hmmm, Ill try that tonight when I have a compiler in front of me. Thanks for the advice!

This topic is closed to new replies.

Advertisement