Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:42:33+00:00 2026-05-20T04:42:33+00:00

My main function contains a string that I would like to jumble. I have

  • 0

My main function contains a string that I would like to jumble. I have found a piece of code which passes in a char* and returns 0 when complete. I have followed the code providers instructions to simply pass in the string which you would like to have jumbled.

#include <iostream>
#include <string.h>
#include <time.h>
using namespace std;

int scrambleString(char* str)
{
     int x = strlen(str);
     srand(time(NULL));
     for(int y = x; y >=0; y--)
     {
          swap(str[rand()%x],str[y-1]);
     }
     return 0;
}

When I do this, I recieve an error that "no suitable conversion function "std::string" to "char*" exists.

I have also tried passing in a const char* but that won’t allow me to access the word and change it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:42:34+00:00Added an answer on May 20, 2026 at 4:42 am

    Why are you mixing std::string with char*? You should just operate directly on the string:

    void scrambleString(std::string& str) 
    {
        int x = str.length();
        for(int y = x; y > 0; y--) 
        { 
            int pos = rand()%x;
            char tmp = str[y-1];
            str[y-1] = str[pos];
            str[pos] = tmp;
        }
    }
    

    Usage becomes:

        std::string value = "This is a test";
        scrambleString(value);
    

    That being said, std::random_shuffle will do this for you…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An example, I have a string that contains let's say: function main { //
So, let's say I have this code (VB.Net): Sub Main() dim xxx as string
I have a legacy database which contains simple data structures (no CODE refs thank
Okay here's the program I have typed up(stdio.h is included also): /* function main
I have a web project that I developed where one of the main functions
My main JavaScript framework is jQuery , so I would like my unit test
I'm having some troubles with binding data. I have an application that contains a
I have a PHP function that returns an array. This is the output of
I came across this piece of code on a website. main(i) { gets(&i); puts();
I need to marshal an array of String^ to call a unmanaged function that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.