Citizen, there is really nothing wrong with your solution except my admittedly rather arbitrary desire not to need so many lines of code every time I want input from the console. My application needs...
Type: Posts; User: maxhavoc
Citizen, there is really nothing wrong with your solution except my admittedly rather arbitrary desire not to need so many lines of code every time I want input from the console. My application needs...
Okay, thanks for the help everyone. I think the lesson I'm taking home from this is don't program in C++ anymore if I ever want to have secure console input.
Ok, that will work so long as I can restrict the number of characters read in from std::cin during the getline() call. Do you know how I can do that?
String does not have a gcount function. When I try to use std::cin.gcount it returns -1.
Is there a way to limit the number of characters getline accepts? I know that std::string simply grows as large as it needs, but this could lead to denial of service attack through resource...
What would that do with the excess input in std::cin? Just silently discard it?
tabstop, that is incredibly obnoxious. Is that really the lengths that you need to go to so that you can accept input safely from the console? Every single time input is required? No wonder there are...
So what you're saying is do something like:
cin.get(inputString, 16);
if (inputString[cin.gcount()] == '\n')
good;
else
bad;
master5001, the problem with that approach is that allows ONLY 16 characters, not up to and including 16 characters.
Ok, when I replace getline with get I no longer need to decrement gcount by 1 to get the actual number of characters read however I still have the same issue with the infinite loop when the user...
The point of asking for help in a forum is to gain the benefit of peoples' experiences. I'm not going to input 2 million some odd characters to see if it breaks if someone else already knows the...
Er...I can never *know* there's going to be extra input. I mean...there has to be a way to accept input safely in C++. There has to be a way to allow for input into a buffer with a fixed upper bound...
cin.ignore() asks for a number of characters to ignore. Is it safe to pass a huge number like INT_MAX to it?
I've already dedicated too much time to this program to replace all my char buffers with std::string. I know how char buffers work. I was mainly hoping there was a way to discard extraneous input...
Ok, I had an inkling that might be the issue. Is there anyway to flush stdin to get rid of any extra input?
I am having two issues with the std::cin.getline() function.
Here is the relevant portion of my code:
std::cout << "Enter administrator password to unlock the database file" << std::endl;
...
Ok, sorry guys, I'm a bit slow. Here's the function I've put together based on nonoob's answer:
void stringToHex(unsigned char* hexString, char* string, int stringLength)
{
unsigned char...
I don't think that will work. I'm reading in characters from a file and I need to convert them to binary. I need one character in an unsigned char array to represent one byte (two characters) from a...
How?
The string is being read from a file with fgets() and being stored in a char*
I am trying to convert a hexadecimal character array to a binary string (unsigned char) that I can use in crypto functions using Cryptlib or OpenSSL. Basically I have a Hex representation of a key...
You're going to need to post a more specific question, give a code example of a particular if statement you are having trouble understanding.
In general they work like this:
if (condition)...
I'm not sure if this is the cause of the problem, but...
#ifdef DRAWING_FUNCTIONS_H
#define DRAWING_FUNCTIONS_H
Should be...
So you don't think Salem's Posix idea will work? Dammit Prelude, you make me sad. Salem seems really smart and he tricked me into thinking that Posix would be my panacea. Your relentless cynicism has...
The problem is that I don't know how to do what I need on every platform, that's why I just want to learn it one way that magically works across all platforms.
And no, I don't plan to distribute...
Do I need to download a Posix API separately? Currently I'm developing under Visual Studio 6 and I can't find opendir or any related function in the MSDN.