Hi,
In a program i want to use the strfry-function. Therefor i've included string.h and used 'extern "C"' to be able to use this function.
But i don't think this is the right way to do it...
Anyone with an idea?
Regards,
Misko
Hi,
In a program i want to use the strfry-function. Therefor i've included string.h and used 'extern "C"' to be able to use this function.
But i don't think this is the right way to do it...
Anyone with an idea?
Regards,
Misko
Just include the header and use the function normally.
Regards
Hi,
In QDevelop i've done: #include <string> and then used the function like this:
lineEditFry->setText(strfry("Test"));
But it gives me a segmentation fault...
Regards,
Misko
Is lineEditFry allocated?
lineEditFry is made (allocated) via the QT-designer and stored in the ui-file...
Without the strfry-part it displays "Test" into lineEditFry.
Try this:
Qt Code:
char *buf="Test"; lineEditFry->setText(strfry(buf));To copy to clipboard, switch view to plain text mode
Or:
Qt Code:
std::string str = "Test"; char *dat = str.c_ptr(); std::random_shuffle(dat, dat+3); lineEditFry->setText(dat);To copy to clipboard, switch view to plain text mode
Or so the same with QByteArray instead of std::string if you're using Qt.
Even in C++ it gives me a segmentation fault:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char *buf = "1235";
cout << strfry(buf) << endl;
}
I know this isn't a real QT-problem, but maybe you can help me out on this one!
I certainly would appreciate!
Regards,
Misko
This works for me:
Qt Code:
#include <iostream> #include <string> int main(){ char buf[16]; strcpy(buf, "12345"); std::cout << buf << std::endl; std::cout << strfry(buf) << std::endl; return 0; }To copy to clipboard, switch view to plain text mode
Works now!!!
strfry is a very handy function when it comes to randomizing strings or even integers, making random permutations possible...
Thanks!
Regards,
Misko
I'd say random_shuffle() is more flexible![]()
I'll check it out!
Thx, Misko
Bookmarks