Punish3r
I can't prompt the user to enter the length of array every time..
Dima
what do you use?
Tushar
Use pointer
BinaryByter
Use pointer
Thank you, he didn't know :)
Punish3r
use std::string or realloc
Using std:: string already.
BinaryByter
then you don't have a fixed size of chars
Punish3r
Thanks, I will try using pointers. And get back if I faced any more issues.
BinaryByter
maybe he's using a less popular implementation of std::string ?
BinaryByter
or he's working on an embedded os that only allows one page for allocation?
BinaryByter
well, that wouldn't make too much sense 🤔
olli
I could imagine is a "string literal" where as this would contradict the "from user" part.
BinaryByter
Yea
Punish3r
or he's working on an embedded os that only allows one page for allocation?
I'm working on linux.. And I am using std::string.. The simple scenario is that whenever user enters a string of more than 4095 chars.. it gets discarded after the 4095th character.
BinaryByter
are you sure that its not an issue with the input stream?
BinaryByter
https://stackoverflow.com/questions/39546500/how-to-make-scanf-to-read-more-than-4095-characters-given-as-input
BinaryByter
Input stream like.?
the input stream is the whole thing that takes a keypress - decodes it - writes it to a buffer - converts it to the required type (nontrivial in case of char* to int)
Punish3r
Nope.. I'm just copying and pasting the string..
BinaryByter
thats the same thing
Punish3r
What do you suggest then.?
BinaryByter
> scanf
should apply to cin
Punish3r
https://stackoverflow.com/questions/39546500/how-to-make-scanf-to-read-more-than-4095-characters-given-as-input
The solution here is to change the terminal from canonical to non-canonical. But what if my program is not OS specific. I want to run it on Linux as well as Windows.
BinaryByter
your problem is os specific
Punish3r
your problem is os specific
You mean if I run it on windows the problem will resolve.?
BinaryByter
i don't know wether the windows CMD buffers like linux
Punish3r
Hmm. What should I i do then..?
olli
You mean if I run it on windows the problem will resolve.?
No, your issue has nothing to do with C++ or C. It's based on the platform you execute your code on.
olli
Hmm. What should I i do then..?
Why do you need to read this huge amount of data?
BinaryByter
I read this as "I want to throw shit because you don't agree with my stance, but I actually have no idea of how this works"
BinaryByter
lol
Punish3r
Why do you need to read this huge amount of data?
To encrypt. 😜 Basically my program is an Encryption algorithm.
BinaryByter
Umm
BinaryByter
you should read /dev/urandom
BinaryByter
also, std::cin should break after every word - meaning that you gotta have a very long word in order for cin not to do what you need
BinaryByter
are you encrypting german?
BinaryByter
if so, theres no need to encrypt it, nobody can understand it anyway ¯\_(ツ)_/¯
BinaryByter
😂
BinaryByter
get line is just wrapping the while loop you'd have to do in order to get stuff from cin
Droid
and scanf\
BinaryByter
scanf is reading until the next space too, iirc
Punish3r
why can't you read a file?
What if user don't want to read data from a file just want to copy the data ecrypt it and then paste the encrypted text back.. You know users can be dumb. 😆
Punish3r
are you encrypting german?
Naah, just English for now. 😀
BinaryByter
Naah, just English for now. 😀
english without any spaces?
Mihail
can the system clipboard even hold that much?
BinaryByter
Punish3r
Which user would copy paste 4K of text?!
4k of chars that would hardly be 10,15 lines of text
BinaryByter
4k of chars that would hardly be 10,15 lines of text
"lines" -> even getline should break in between
Punish3r
english without any spaces?
getline don't break until \n
BinaryByter
getline don't break until \n
it uses cin internally
BinaryByter
unless you are giving it another stream
Punish3r
"lines" -> even getline should break in between
I'm using the text that comes as single line
BinaryByter
I'm using the text that comes as single line
I can't think of any text that comes as a single word as a single line
BinaryByter
and again: you can't solve that borderline without using system specific code
BinaryByter
so i'd not bother too much about it ¯\_(ツ)_/¯
olli
The solution here is to change the terminal from canonical to non-canonical. But what if my program is not OS specific. I want to run it on Linux as well as Windows.
long story short. If you want to have it work cross plattform in ISO C/C++ and don't write system dependant code, read a file. There is no other solution
BinaryByter
BinaryByter
and POSIX is not to ununiversal
Daniele°
You not like fgets?
BinaryByter
You not like fgets?
do you know what fgets stands for? 😊
Dima
and POSIX is not to ununiversal
Talk about windows api 😉
BinaryByter
Talk about windows api 😉
nt complies to posix mostly though
Dima
I wish it was tho.
BinaryByter
File get string?
Wonderful! He knows what it stands for :)
BinaryByter
Now, why don't we make him tell us what "file get string" means ?
BinaryByter
I wish it was tho.
https://en.wikipedia.org/wiki/Microsoft_POSIX_subsystem