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

The Archive Base Latest Questions

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

I need to know if this StrBuff struct is supposed to operate like an

  • 0

I need to know if this StrBuff struct is supposed to operate like an array. I’ve looked and looked, and honestly can’t tell just due to the pointer syntax – it seems like as an array it could work, and as an array it could not work.

I see that in the second method, malloc() is used, so I’m guessing that the buf-str uChar is supposed to be an array.

Teh codez:

typedef struct {
    unsigned char *str;
    unsigned int len;
} StrBuf;


static StrBuf *
strbuf_new ()
{
    StrBuf *buf;

    buf = (StrBuf *) calloc (sizeof (StrBuf), 1);
    buf->str = (unsigned char *) strdup ("");
    return buf;
}


static void
strbuf_append (StrBuf *buf, unsigned char *data, int len)
{
    int offset;

    if (len <= -1)
        len = strlen ((char *) data);
    offset = buf->len;
    buf->len += len;
    buf->str = (unsigned char *) realloc (buf->str, buf->len + 1);
    memcpy (buf->str + offset, data, len);
    buf->str[buf->len] = '\0';
}

So, judging from these methods I’m guessing for any C/C++ veterans out there this should be a piece of cake.

Edit:

My goal has been to convert an app (which uses this code here) into a Java port, but I’ve been quite confused as to how I should do it. I’ve gotten fairly far doing (for the most part) the same thing in Java, only this time using a byte[] array, seeing as how unsigned chars are supposed to be equivalent to bytes in Java.

  • 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-23T04:21:53+00:00Added an answer on May 23, 2026 at 4:21 am

    It’s not an array. It’s a structure to hold values (probably strings) using dymamic memory allocation. If you use an array to allocate some datas, then array size is determined at compile time.
    For example:

    char buf[10];
    

    With a structure like StrBuf you can allocate the required memory when the string buf of the given length is supplied :

    buf->str = (unsigned char *) realloc (buf->str, buf->len + 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems so basic, I can't believe I don't know this! I just need a
I have solved this problem, I just need to know what to do. I
Now this may seem like a silly question, but I need to know how
I have just started PHP and mySQL and need to know if this is
I need to know what this UI component is called ? It looks like
Need to know this so that i could send DTMF and that is going
I need to know this since this is a pre-req for .NET 3.5 and
I know this is a very broadly scoped question, but what do I need
I need to know when I click on an element if this element has
I don't know if this is a right question, but i need to understand

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.