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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:57:44+00:00 2026-06-08T16:57:44+00:00

I have a struct like this: static struct F_t { char *_1; char *_2;

  • 0

I have a struct like this:

static struct F_t {
  char *_1;
  char *_2;
  char *_3;
  char *_4;
  char *_5;
  char *_6;
  char *_7;
  char *_8;
  char *_9;
  char *_10;
  char *_11;
  char *_12;
} F = { 0 };

According to some values from stdin, it’s set properly.

The “problem” is that I retrieve it from string, and I need set it properly. I’m using this function currently:

static inline void 
setf(int i, char *value)
{
  /* Nothing to do. */
  if(i > 12)
    return;

  if(i == 1)
    F._1 = value;
  else if(i == 2)
    F._2 = value;
  else if(i == 3)
    F._3 = value;
  else if(i == 4)
    F._4 = value;
  else if(i == 5)
    F._5 = value;
  else if(i == 6)
    F._6 = value;
  else if(i == 7)
    F._7 = value;
  else if(i == 8)
    F._8 = value;
  else if(i == 9)
    F._9 = value;
  else if(i == 10)
    F._10 = value;
  else if(i == 11)
    F._11 = value;
  else if(i == 12)
    F._12 = value;
}

I’ve tried by using macros.. but as it’s set in run-time, it will not possible. I know that if have no reflections, modern things like this, etc. But maybe there is something that I do not know. Probably it’s possible in C++. But no. I want pure C.

Any suggestion is very appareciated. Thanks in advance.

  • 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-08T16:57:45+00:00Added an answer on June 8, 2026 at 4:57 pm

    Why don’t you just do this:

    static struct F_t {
        char ** _;
    } F = { 0 };
    

    At this point, just make sure you malloc for the double array of size 12 (in your case) and then you can have a function as follows:

    setf(int i, char *value)
    {
         F._[i] = value;
    }
    

    Things look a lot better no?

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

Sidebar

Related Questions

I have a struct like this typedef struct bookStruct { char title[80]; char author[80];
If I have a struct like this: typedef struct { unsigned char c1; unsigned
So I have something like this #define HASHSIZE 1010081 static struct nlist *hashtab[HASHSIZE]; Now
I currently have a class like this: struct Rgb { static const int NUM_CHANNELS
Ok so I have struct like this typedef struct { float x; float y;
Hi I have a struct like this typedef struct { string firstname; string lastname;
I have a C struct like this: typedef struct { my_domain_type_t type; my_domain_union_t u;
I have a struct that looks like this: typedef struct _my_struct { float first_vector[SOME_NUM][OTHER_NUM];
I have a struct that's defined like this: struct Vec3 { float x, y,
For example, I have a struct which is something like this: struct Test {

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.