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 8378003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:49:12+00:00 2026-06-09T15:49:12+00:00

I am making a program in C++ using Xcode that will generate random strings

  • 0

I am making a program in C++ using Xcode that will generate random strings but when I do this it consumes an incredible amount of RAM. I have tried using .erase(); and .clear(); but neither seems to work.

here is my code:

void randStringMake(char *s, int l)
{
    // AlphaNumaric characters
    static const char AlphaNumaric[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "1234567890";

    for(int x = 0; x < l; x++) {
        s[x]=AlphaNumaric[rand() % (sizeof(AlphaNumaric) - 1)];
    }
    s[l] = 0;
}

char randString;

randStringMake(randString, 10);

std::cout << std::string(&randString) << "\n";

So i guess my question here, is how do i remove the string from the memory?

  • 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-06-09T15:49:14+00:00Added an answer on June 9, 2026 at 3:49 pm

    I made some minimal changes to your code so it compiles and runs. The main problem was randString was declared as a single char when it should be an array large enough to hold the generated string and a null terminator.

    Note that the code as posted doesn’t required std::string and shouldn’t cause excessive memory use. If you still have a problem it’s in code that you haven’t shown.

    #include <iostream>
    #include <cstdlib>
    
    void randStringMake(char *s, int l)
    {
        // AlphaNumaric characters
        static const char AlphaNumaric[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "1234567890";
    
        for(int x = 0; x < l; x++) {
            s[x]=AlphaNumaric[rand() % (sizeof(AlphaNumaric) - 1)];
        }
        s[l] = 0;
    }
    
    int main()
    {
        // randString should be an array to hold 10 chars + null terminator
        char randString[11];
    
        randStringMake(randString, 10);
    
        std::cout << randString << "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a program that communicate with certain patient monitor using C sockets. I'm
I'm making a Java program that can solve the roots using the quadratic equation
I have this bizarre problem. I'm making a checklist program with XCode and I'm
I'm making a program using RBing. But I unable to get 50 links. How
If I made a program that stores strings on a text file using the
I'm making a typing tutor program using javascript. Everything is going well except that
I am making my first program using Java3D. I have setup some transformGroups that
I'm making a program that is using Windows Shell Integration, and the registry changes
I am making a command line program in C using XCode. When running the
I am making a program, in C++ using Visual Studio 2005, that needs to

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.