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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:15:42+00:00 2026-05-31T10:15:42+00:00

I am creating a thread for each request from the client to get the

  • 0

I am creating a thread for each request from the client to get the files on the server. Thread function normally gets a void pointer; but I need to give it a char pointer as a parameter and want it to be populated with the file names by the thread function.

Code creates a thread:

pt_ret = pthread_create(&thread_id, NULL, getfiles, (void*) thread_buff);
pthread_join(thread_id, pt_ret);

Def. of thread function:

void *getfiles(void *ptr) {
    /* ... */
    char buff[256]; // populating that local buffer with the file names
    // ptr should be as a return of buff
}

I have tried different things but each time after that thread completes, thread_buff becomes just ‘Q’.

  • 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-31T10:15:43+00:00Added an answer on May 31, 2026 at 10:15 am

    Just cast it to a char*, since you know it actually is a char*:

    void *getfiles(void *ptr) {
        /* ... */
        const char *ptr_char = (const char*)ptr;
        char buff[256]; 
        memcpy(buff, ptr_char, 256); //just as an example, check the sizes.
        //you could also strcpy, that's up to you
    }
    

    Or you could also just work on the buffer pointed by ptr, without copying it, so it’s accessible after the thread has ended:

    void *getfiles(void *ptr) {
        /* ... */
        char *buff = (char*)ptr;
        /* do stuff with buff. */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using vc++ and creating a thread using CreateThread function .Can I restart
I am creating a socket server in C# and a client in PHP. The
The Java tutorials say that creating a Thread is expensive. But why exactly is
I am creating 5 thread here using ThrdFunc. Here each thread update the listBox.
I'm trying to make a simple HTML server that will read a request from
while creating a thread in java, there is two ways such as Extending threads
I'm creating a thread class to encapsulate the windows thread methods. I'm trying to
I am working on creating a thread safe control for my windows forms application.
pthread_create returns the value 251 without creating the thread. Does anyone know what the
In a WPF application I had a BackgroundWorker thread creating an object. Let's call

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.