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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:27:10+00:00 2026-05-10T21:27:10+00:00

I have a couple of array’s: const string a_strs[] = {cr=1, ag=2, gnd=U, prl=12,

  • 0

I have a couple of array’s:

const string a_strs[] = {'cr=1', 'ag=2', 'gnd=U', 'prl=12', 'av=123', 'sz=345', 'rc=6', 'pc=12345'}; const string b_strs[] = {'cr=2', 'sz=345', 'ag=10', 'gnd=M', 'prl=11', 'rc=6', 'cp=34', 'cv=54', 'av=654', 'ct=77', 'pc=12345'}; 

which i then need to parse out for ‘=’ and then put the values in the struct. (the rc key maps to the fc key in the struct), which is in the form of:

struct predict_cache_key {     pck() :         av_id(0),         sz_id(0),         cr_id(0),         cp_id(0),         cv_id(0),         ct_id(0),         fc(0),         gnd(0),         ag(0),         pc(0),         prl_id(0)     { }      int av_id;     int sz_id;     int cr_id;     int cp_id;      int cv_id;     int ct_id;     int fc;     char gnd;     int ag;     int pc;     long prl_id; }; 

The problem I am encountering is that the array’s are not in sequence or in the same sequence as the struct fields. So, I need to check each and then come up with a scheme to put the same into the struct.

Any help in using C or C++ to solve the above?

  • 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. 2026-05-10T21:27:10+00:00Added an answer on May 10, 2026 at 9:27 pm

    This shouldn’t be too hard. Your first problem is that you don’t have a fixed sized array, so you’d have to pass the size of the array, or what I’d prefer you make the arrays NULL-terminated, e.g.

    const string a_strs[] = {'cr=1', 'ag=2', 'gnd=U', NULL};

    Then I would write a (private) helper function that parse the string:

     bool parse_string(const string &str, char *buffer, size_t b_size, int *num) {     char *ptr;      strncpy(buffer, str.c_str(), b_size);     buffer[b_size - 1] = 0;      /* find the '=' */     ptr = strchr(buffer, '=');      if (!ptr) return false;      *ptr = '\0';     ptr++;      *num = atoi(ptr);      return true; } 

    then you can do what qrdl has suggested.

    in a simple for loop:

     for (const string *cur_str = array; *cur_str; cur_str++) {    char key[128];    int value = 0;     if (!parse_string(*cur_string, key, sizeof(key), &value)        continue;     /* and here what qrdl suggested */    if (!strcmp(key, 'cr')) cr_id = value;    else if ... } 

    EDIT: you should probably use long instead of int and atol instead of atoi, because your prl_id is of the type long. Second if there could be wrong formated numbers after the ‘=’, you should use strtol, which can catch errors.

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

Sidebar

Ask A Question

Stats

  • Questions 59k
  • Answers 59k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You'd be calculating the eigenvectors of a 2x2 matrix, which… May 11, 2026 at 9:00 am
  • added an answer -Wsign-compare May 11, 2026 at 9:00 am
  • added an answer You can use string format codes in your ToString call. May 11, 2026 at 9:00 am

Related Questions

I have a couple of questions regarding VBScript and ASP Classic: What is the
I have a couple of files containing a value in each line. EDIT :
I have a couple of header files, which boil down to: tree.h: #include element.h
I have a couple of triggers on a table that I want to keep
I have a couple of solutions, but none of them work perfectly. Platform ASP.NET
I have a couple of questions about generic wildcards in Java: What is the
I have a couple of Divs which I style using a class and an
I have a couple of array's: const string a_strs[] = {cr=1, ag=2, gnd=U, prl=12,
I have a couple of hobby C programming projects that I would like to
I have a couple of tables in my database, one called Task , and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.