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

  • Home
  • SEARCH
  • 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 4061990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:32:31+00:00 2026-05-20T15:32:31+00:00

Hey everyone, thanks for taking the time to address my problem. I’ve looked at

  • 0

Hey everyone, thanks for taking the time to address my problem. I’ve looked at so much material at this point that I’ve just started getting more and more confused. Basically, I’m writing a simple segment of code that parses a string. Please understand that my question is NOT about parsing. I am using C++ and have never used C before and possess a little bit of c++ experience (introductory experience, I’m still a newbie).

struct parsedString{
char chunk1[50];
char chunk2[10];
char chunk3[50];
};

main(char* bigstring)
{
    parsedString ps;
    ps = parseMe(bigString)
    cout << ps.chunk1 << endl;
    cout << ps.chunk2 << endl;
    cout << ps.chunk3 << endl;
}

parsedString parseMe(char* stringToParse)
{ 
    char* parseStr = stringToParse; 
    parsedString ps; 
    ps.chunk1 = first x chars; 
    ps.chunk2 = next y chars;
    ps.chunk3 = last z chars; 
    return ps;
}

Obviously this is not working code, I didn’t want to throw up all the extra stuff since it would be tougher to read through and I’m pretty sure my problem is a newbie c/c++ problem and something about memory allocation or something like that…

Basically when the main function gets to printing the strings from the parsedString it prints out exactly what I want it to, plus garbage characters. I’m entering the values for each array ps.chunk using

ps.chunk1[i] = *parseStr

since parseStr gets me each individual character. I can’t figure out where the garbage characters are coming from, does it have something to do with how I am accessing the big string? Originally I used char in the struct instead of arrays and when I printed from within the parseMe() function they would come out great but they would turn into gibberish when I accessed it from the main function. Any help is appreciated, thanks so much.

If something is unclear please let me know I’ll do my best to elaborate.

  • 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-20T15:32:32+00:00Added an answer on May 20, 2026 at 3:32 pm

    It’s not clear why you’re trying to do this with '\0' terminated
    strings, when C++ has a perfectly usable string class, but
    supposing some pedagogical reasons: are your strings '\0'
    terminated? How do you extract and copy the first x chars into
    ps.chunk1? How do you ensure that it has a '\0'?

    If you really want to get exactly n characters, you have to:

    assert(strlen(parseStr) >= n);
    

    , copy them into the target (which must contain at least n+1 char’s),

    memcpy(ps.chunk1, parseStr, n);
    

    , and add the final '\0':

    ps.chunk1[n] = '\0';
    

    (And, of course, advance parseStr: parseStr += n;)

    Or you can simply use std::string everywhere, and write
    something like:

    ps.chunk1(stringToParse.substr(startPosition, length));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone and thanks for taking the time to help. I am stuck on
Hey everyone. I've written this simple function that is supposed to load a portion
Hey everyone I'm currently extremely frustrated and can not figure this out have looked
Hey everyone.. This is my first time writing an ASP.NET MVC web app, and
Hey everyone I am having a little problem with my jQuery I am trying
Hey everyone. The following is the code that I am using to play random
Hey everyone, just a quick thing, I have the hex to integer working, but
hey everyone, here is the site SEE BELOW I have a slight jquery problem
Hey everyone, this seems like it should be a simple one; I really hope
Hey everyone. I am having some issues on my end and hopefully it's just

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.