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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:45:52+00:00 2026-05-27T22:45:52+00:00

I want to hide a specified struct in my c module, so struct declaration

  • 0

I want to hide a specified struct in my c module, so struct declaration is in the *.c file and the header contains a typedef. Something like this:

/* member.h */
typedef struct MEMBER_T *member_t;

/* member.c */
#include "member.h"
struct MEMBER_T {
    unsigned int member_id;
    char name;
};

and later in the c file I want to do a member table:

members = calloc(10, sizeof(member_t));

but it’s wrong, I know.
How can I use thie solution? I mean how can I create an object for member_t?

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-05-27T22:45:53+00:00Added an answer on May 27, 2026 at 10:45 pm

    You are allocating an array. you still need to allocate each of its elements.

    If you want to hide the struct in .c file, than it would also be a good idea to encapsulate its creation. So the user of you struct will not ha to bother whether to user sizeof(member_t) or sizeof(*member_t) or sizeof(struct MEMBER_T).

    define a function membet_t* create_member_array(int) in you header in addition to typedef struct MEMBER_T* member_t.

    implement it in you .c file

    member_t* create_member_array(int length) {
        member_t* arr = (member_t*) malloc(length * sizeof(member_t));
        if(arr) {
            int i = 0;
            for(; i < length; i++) {
                arr[i] = (member_t) malloc(sizeof(struct MEMBER_T));
                if(arr[i]) {
                    arr[i]->member_id = 0;
                    arr[i]->name = NULL;
                }
            }
        }
        return arr;
    }
    

    the declaration in you struct char name; combined with the statement members[0]->name = "test" is not correct. You declar a single char and try to a ssign a string to it, witch itself is not correct. it should be char* name and you shold allocate mememory before trying to copy a string to ist using strcpy()

    member[0]->name = malloc((strlen("test") + 1)  * sizeof(char)); // 1 more the terminating '\0' !
    strcpy(member[0]->name, "test");
    

    alternativ:

    member[0]->name = strdup("test");
    

    This is a lot of memory allocation witch you need to make sure you release / free it. You will have to create another function to free all this memory

    void free_member_array(member_t* members, int length) {
        for(int i = 0; i < length; i++) {
            if(members[i]->name) {
                free(members[i]->name);
            }
            free(members[i]);
        }
        free(members);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to hide a specific div element, the name of which contains $
Right let’s get this out the way first. Yes, I want to hide the
My application uses multiple windows I want to hide one specific window in case
I want to hide the selected item from the opened WPF combo box, basically
I want to hide the Next button on my ASP.NET Wizard control using JavaScript.
I want to hide the cursor when showing a webpage that is meant to
I want to hide all mysql error messages without using mysql_error() . Are there
I want to hide the titlebar of my app in some of my views.
I want to hide all the descendents of the ul for my tree menu
I want to hide these fieldsets in a Drupal 6 site for some content

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.