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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:21:10+00:00 2026-05-23T01:21:10+00:00

another linked question is Segmentation fault while using strcpy()? I have a structure: struct

  • 0

another linked question is Segmentation fault while using strcpy()?

I have a structure:

struct thread_data{    
    char *incall[10];
    int syscall arg_no;    
    int client_socket;
 }; 

How do I initialize a pointer to a structure of type above as well as initialize the pointer to the 10 strings (incall[]) inside the structure.

Do I first initialize the strings and then the structure.

Thanks.

An edit: I guess I used the wrong word and should have said allocate. Actually I am passing this structure as an argument to threads. No. of threads is not fixed and the data structure sent as argument must be unique for each thread and “thread safe” i.e cannot be changed by other threads.

  • 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-23T01:21:10+00:00Added an answer on May 23, 2026 at 1:21 am

    Here’s the answer to the question I think you’re asking:

    /**
     * Allocate the struct.
     */
    struct thread_data *td = malloc(sizeof *td);
    
    /**
     * Compute the number of elements in td->incall (assuming you don't
     * want to just hardcode 10 in the following loop)
     */
    size_t elements = sizeof td->incall / sizeof td->incall[0];
    
    /**
     * Allocate each member of the incall array
     */
    for (i = 0; i < elements; i++)
    {
      td->incall[i] = malloc(HOWEVER_BIG_THIS_NEEDS_TO_BE);
    }
    

    Now you can assign strings to td->incall like so:

    strcpy(td->incall[0], "First string");
    strcpy(td->incall[1], "Second string");
    

    Ideally, you want to check the result of each malloc to make sure it was successful before moving on to the next thing.

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

Sidebar

Related Questions

I have a SQLServer with a linked server onto another database somewhere else. I
Another basic Rails question: I have a database table that needs to contain references
This is linked to another question/code-golf i asked on Code golf: "Color highlighting" of
This IS kind of linked to another question - Code golf: "Color highlighting" of
I dont understand DatePeriod, DateInterval classes very well. This question is linked to another
I have a variable number of modules linked to another module via a signal
Another easy one hopefully. Let's say I have a collection like this: List<DateTime> allDates;
Another poster asked about preferred syntax for infinite loops . A follow-up question: Why
Another question asked about determining odd/evenness in C, and the idiomatic (x & 1)
Another clipboard question: When text is put onto the clipboard, it frequently goes in

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.