Anonymous
Fgets() requires enter to be hit twice after reading to char array (only if stdin is empty)
Anonymous
exemple 1: data.txt | ./exec -c 123456 ( it works only by clicking once on enter)
Anonymous
exemple2: ./exec -c 123456( I need to click twice on enter)
Anonymous
I tried this with no sucess
Anonymous
any help will be greatly appreciated *
Anonymous
👍
Nicola
how can I randomly exchange the characters of a string?
Anonymous
@NICOOH
std::string blah = "BLAH";
random_shuffle( blah.begin(), blah.end() );
Nicola
[Error] could not convert 'std::random_shuffle<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >(s.std::basic_string<_CharT, _Traits, _Alloc>::begin<char, std::char_traits<char>, std::allocator<char> >(), s.std::basic_string<_CharT, _Traits, _Alloc>::end<char, std::char_traits<char>, std::allocator<char> >())' from 'void' to 'std::string {aka std::basic_string<char>}'
Nicola
😭😭😭😭😭
Nicola
How to solve?
Anonymous
compiles under gcc 8.2
Anonymous
https://godbolt.org/z/VJnO9g
E
anyone know that what is wrong here. i use header file conio.h but wenn i compile it gave a error there is no header file.i think that is impossible what can i do ?
Anonymous
good to know @vehlwn, thx
E
Ludovic 'Archivist'
Ludovic 'Archivist'
Give us details
Ludovic 'Archivist'
And what you tried to solve the problem
Ludovic 'Archivist'
Even if I already know the solution
Ludovic 'Archivist'
He is on VS
Ludovic 'Archivist'
Like I said, I know how to solve his problem but will not do if he makes no efforts
E
ok let,s me explain it a few minute later it's ok ?
Ludovic 'Archivist'
#howtoask
Ludovic 'Archivist'
Oh yeah that's what I wanted
Anonymous
I've tried random_shuffle() with VS 2017 Community Edition. Works perfectly fine. The sample compiles, linkes and executes...
Ludovic 'Archivist'
Ludovic 'Archivist'
Or something along those lines
Anonymous
sure @QNeko . I just wanted to understand what the problem is with random_shuffle() on VS 2017. shuffle() is the way to go
Ludovic 'Archivist'
Ludovic 'Archivist'
And replaced by a
using random_shuffle = void;
Anonymous
Perhaps. But good to know, that random_shuffle() is removed by the standard even if the compilers have not adopted it yet or it is compiler flag depended.
Ludovic 'Archivist'
[Error] could not convert 'std::random_shuffle<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >(s.std::basic_string<_CharT, _Traits, _Alloc>::begin<char, std::char_traits<char>, std::allocator<char> >(), s.std::basic_string<_CharT, _Traits, _Alloc>::end<char, std::char_traits<char>, std::allocator<char> >())' from 'void' to 'std::string {aka std::basic_string<char>}'
Oh wait that is gcc
Ludovic 'Archivist'
So yeah removed
Ludovic 'Archivist'
Gone
Ludovic 'Archivist'
Anonymous
"[...] from 'void' to 'std::string {aka std::basic_string<char>}'"
now I see. You are right @QNeko :)
Ludovic 'Archivist'
Nicola
Anonymous
hmm according to compiler explorer, the code compier under 4.9.2, too
https://godbolt.org/z/-aX7F3
But as already said, shuffle() is the way to go as random_shuffle() is depricated
Anonymous
Hi
Nicola
[Error] ld returned 1 exit status
Nicola
I'm nervous
Nicola
ahahaah
Anonymous
Hello guys. I dont understand the logic of this: char *p=“abcd”;
Anonymous
Pointers point an adress right ? Does “abcd” even have an address ?
Vitaliy ◀️TriΔng3l▶️
Well… it exists somewhere it memory
Anonymous
Shouldnt we do this char ch[]=“abcd”; so it can have an address
Vitaliy ◀️TriΔng3l▶️
They both do
Vitaliy ◀️TriΔng3l▶️
But
Vitaliy ◀️TriΔng3l▶️
char ch[] = "abcd"; is a special kind of initialization of char arrays as far as I know
Vitaliy ◀️TriΔng3l▶️
It will create an unique instance of char ch[] = { 'a', 'b', 'c', 'd', '\0' }; that you will be able to modify the contents of
Vitaliy ◀️TriΔng3l▶️
char *p = "abcd"; is not really safe because in this case "abcd" may be created in read-only memory, may be created only once in the entire compiled object file or program
Vitaliy ◀️TriΔng3l▶️
const char *p = "abcd"; is safe
Vitaliy ◀️TriΔng3l▶️
But there will be differences regarding sizeof also
Vitaliy ◀️TriΔng3l▶️
The same as between any array and any pointer
Anonymous
Okay, I guess I understand
Anonymous
Thank you
Parra
Nicola
Anonymous
It worked for me in VS 2017. I've tried it some minutes ago @NICOOH
I honestly don't understand what is different on your system
BinaryByter
@NICOOH are you an organic acid?
BinaryByter
@ariana1429 was my pun good?
Nicola
Nicola
Anonymous
Sure, send it. I'm curious why it is working on my machine but not on yours
BinaryByter
wrong compiler version?
Anonymous
@linuxer4fun I tried it with the same compiler version with the online compiler. it compiled well
Nicola
it does not send me the link
Anonymous
Try to post the plain source code if it is not much. I hope this is allowed for new users
Nicola
#include <iostream>
#include <string>
#include <time.h>
#include <windows.h>
#include <stdio.h>
using namespace std;
string PBOX1(string s){
string s1;
s1=random_shuffle(s.begin(),s.end());
return s1;
}
int main(int argc, char** argv) {
string s1;
cin>>s1;
cout<<s1;
string s2=PBOX1(s1);
cout<<endl<<s2;
return 0;}
Anonymous
aaaah
Anonymous
I see
Anonymous
#include <algorithm>
Anonymous
random_shuffle() doesn't return anything, it modifies your input
Anonymous
so remove the assignment to s1
Anonymous
or just... wait a sec ;)