Jump to content
  • Advertisement
Sign in to follow this  
silverphyre673

I made a console formatting (color, cursor position) object

This topic is 4816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yeah... for those of you (and I know there is a lot of you) who want to be able to use color, position the cursor, or get user input without displaying what the user typed (or overwrite it with '*' like a password), and are using Windows (for now), I made this file. You can get it from the coding download section of my site at home.comcast.net/~silverphyre673/index.html Please let me know what you think. You can use it for anything you like, and, as the tutorial says, it is only version 0.5 (write and read functions need a bit of work). Please read the tutorial before asking questions, but ANY improvements will be really welcome. Thanks for trying it out - let me know what you think! Hey Drew! :D Yay Composer. Quick fix. Anyways, I've been overloading the read/write function, but left SetWrite and MoveWrite templated so they now just call Write on whatever is passed to them, which I think should work. So... question: If Read() takes a char* that is supposed to be read into (it doesn't return the read value, it puts it into readObj), do I just use Read(char* buffer) or Read(char* &buffer) <-- Seems ugly to me! Thanks, guys! [Edited by - silverphyre673 on March 14, 2005 11:07:26 PM]

Share this post


Link to post
Share on other sites
Advertisement
To make your links clickable, use <a href="url goes here">link text goes here</a>
(you've also gotta make sure that there's an http:// in there or the link will end up pointing somewhere on these forums)
e.g. Your website

p.s. please don't [repost] the same thing in multiple forum sections.

Share this post


Link to post
Share on other sites
Accident. I thought it didn't post, and my browser started freezing, so I closed it, then accidentaly posted on the other forum. yeah. But please try it out.

Share this post


Link to post
Share on other sites
Looks interesting. I'm not sure why you have templated many of the functions though, especially when you are using strlen() on that template object in one part of your code.

Share this post


Link to post
Share on other sites
Haven't look at your code yet, but I do appreciate the web page change. That last one got me kind of depressed when I looked at the game of life [lol]

Share this post


Link to post
Share on other sites
Actually, and I guess I should update the readme about this, but I could use some help with the Read functions...

In case you didn't see (I modified the original post, so you might have missed it)

Hey Drew! :D Yay Composer. Quick fix. Anyways, I've been overloading the read/write function, but left SetWrite and MoveWrite templated so they now just call Write on whatever is passed to them, which I think should work. So... question: If Read() takes a char* that is supposed to be read into (it doesn't return the read value, it puts it into readObj), do I just use

Read(char* buffer)

or

Read(char* &buffer) <-- Seems ugly to me!

Thanks, guys!

Also, the Read(std::string, unsigned length) function is being crappy and appends random characters to the end of my strings. Could someone show me why, maybe? Thanks!

Share this post


Link to post
Share on other sites
You should use Read(char *buffer) since you arent changing where the pointer points to.

Also, I do not believe that ReadConsole() will add the null terminator to your string. You should use the return value to put the null terminator into your buffer.

Share this post


Link to post
Share on other sites
Quote:

Also, I do not believe that ReadConsole() will add the null terminator to your string. You should use the return value to put the null terminator into your buffer.


How would this look? Here is the function now:


bool Console::Read( char * readObj, unsigned length )
{
DWORD read=0;
if ( !ReadConsole(input_handle, readObj, length, &read, NULL) )
return false;
readObj[strlen(readObj)+1]='\0';
return true;
}


But this doesn't seem to work.

Share this post


Link to post
Share on other sites
I've never used ReadConsole before, but doesn't strlen() just return the position of the first null terminator? So you're going to need another way of determining the length.

EDIT: Just noticed...that'd be the variable "read" :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!