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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:04:19+00:00 2026-05-26T22:04:19+00:00

Trying to use as basic C as I can to build a list of

  • 0

Trying to use as basic C as I can to build a list of numbers from 1-52 in a random order (deck of cards). Everything works, but all of my attempts to concat the strings and get a result end in failure. Any suggestions? NOTE: This is not homework it’s something I’m using to create a game.

// Locals
    char result[200] = "";  // Result
    int card[52];           // Array of cards
    srand(time(0));         // Initialize seed "randomly"

    // Build
    for (int i=0; i<52; i++) {
        card[i] = i;  // fill the array in order
    }

    // Shuffle cards
    for (int i=0; i<(52-1); i++) {
        int r = i + (rand() % (52-i));
        int temp = card[i]; card[i] = card[r]; card[r] = temp;
    }

    // Build result
    for (int c=0; c<52; c++) {

        // Build
        sprintf(result, "%s%d", result, card[c]);

        // Comma?
        if ( c < 51 )
        {
            sprintf(result, "%s%s", result, ",");
        }
    }

My end result is always garbled text. Thanks for the help.

  • 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-26T22:04:20+00:00Added an answer on May 26, 2026 at 10:04 pm

    Are we writing C++ or C? In C++, concat-ing a string is just:

    string_out = string_a + string_b
    

    …since you’d be using std::string.

    Furthermore, if this is C++, the STL has a std::shuffle function.

    If this is C, note that all your sprintfs aren’t concatenating strings, they’re just overwriting the old value.

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

Sidebar

Related Questions

I'm trying to use the Server class from Cassini to include a basic web
I'm trying do to a basic bash with the use of system calls but
I'm trying to use mono to build a C# application for linux. But it
I'm trying to use SQLAlchemy to implement a basic users-groups model where users can
We are trying to use a basic @OneToMany relationship: @Entity @Table(name = PARENT_MESSAGE) public
I'm trying to use operator overloading to define the basic operations (+,-,*,/) for my
I'm trying to use FireWatir (1.6.5) to access a site using Basic Authentication and
So, I'm trying to use Doctrine to retrieve some data. I have some basic
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying to use FormCheck for MooTools to validate a basic contact form

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.