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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:11:30+00:00 2026-05-30T07:11:30+00:00

I’m trying to write a program that finds strings in a character array and

  • 0

I’m trying to write a program that finds strings in a character array and output the strings randomly as well as output string number and length. The trouble I seem to be having is picking out the length. I’m not sure if I should use the length stored in the comment (if it can even do that) or count each character and output the length that way. I’m not really sure how to do that though.

char * strings [] ={

// String 1 of 5000:  Length = 185
"J1{GW3_%-3s_%p*E<ed<qLB#YHN%S8.odr5|[QPz&Hslk#3vi[)T3wgh3lHdVtTGz|M1RsGy_r=J]Rgp`0+s)pbvpm<u'8NsPX:Uk)kU,d5t@w[{2efjt*z_`eOqa#iP3z)T<(eYWb%W{5g?ynp*<jfEeLUA5:ukgvw$Le,Yjv*o{a/,tV#dG1|+D", 

// String 2 of 5000:  Length = 9
"^PuU]gjh)", 

}

Right now I’m using a rand function to output 5,000 strings to an output file like so

outfile1 << strings[rand()%5000] << endl;

This function is nested within a loop and it seems to output it randomly, but it’s the same random pattern every time, so maybe I should seed the rand function differently.

Anyway, I really am lost when it comes to showing the length of each string in the output file. Does anyone have any suggestions as to how I can do this? This is homework so I’d like some information on how to apply this rather than a straight answer. 🙂

As of now my output is this:

#11 (Length:168) - JZn'TGF&#K=EohoZT
#12 (Length:189) - DiF9ao^T,7rtQ#Yc>n{_YIG_y
#13 (Length:50) - y,|l2;hA;H;pHz?|jLADh

As you can see, the strings output correctly but the length is incorrect.

  • 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-30T07:11:31+00:00Added an answer on May 30, 2026 at 7:11 am

    ///Updated answer//

    I think what you want to do is to output each string in the array and calculate each of their length right??? I wrote this quick program and it worked fine.

    char* strings[] = {"hellothisistom", "nicetomeetyou"};
    
    for (int i = 0; i<2; i++)
    {
        int k = rand()%2;
        cout<< strings[k] << endl;
        cout<< strlen(strings[k])<<endl;
    
    }
    

    You can replace cout with your output file string.
    Make sure you use the same k to get both the string and the length!

    ////////////////////////////////////////////////

    A character is a one-bit character such as ‘A’, ‘b’, ‘%’, etc.
    A character string is simply an array of characters.
    On the other hand, a string is a special class that represent a series of characters.

    Character String, works like a normal array.
    In your case, the strings (which is a character array), you can just use sizeof(strings)/sizeof(strings[0]) to find out the number of characters.

    As you mentioned, that character string is made up of many short strings. Unless there are some special characters that separate the words, there is no way (at least not easy way) to separate the string of characters into words.

    For example if your character string is hellothisistom. There is no way to separate the words… unless you go into natural language processing.
    If your character string is like hello/this/is/tom, which there is some thing that separates individual words, then you can use many kinds of methods to extracts the words. You can check out the site below for the tools that you can use.
    http://www.cplusplus.com/reference/clibrary/cstring/

    For example, in a loop you can search for the first occurrence of that special character and search for the one after that. Then you just copy the characters in between, output those characters and and size (using that method mentioned above). Then move on to the next one.

    When you output stings[rand()%5000], won’t there be just a bunch of random characters inside strings?

    • 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 string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I need to write an AS3 program to search for a certain keyword in
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.