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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:34:55+00:00 2026-06-11T18:34:55+00:00

I have a really irritating problem. This is the buffer structure i am using

  • 0

I have a really irritating problem. This is the buffer structure i am using

typedef struct BufferDescriptor {
   char * ca_head ;    /* pointer to the beginning of character array (character buffer) */
   int capacity ;      /* current dynamic memory size (in bytes) allocated to character buffer */       
   char inc_factor;    /* character array increment factor */
   int addc_offset ;    /* the offset (in char elements) to the app-character location */
   int mark_offset ;   /* the offset (in chars elements) to the mark location */
   char r_flag;        /* reallocation flag */
   char mode;          /* operational mode indicator*/

} Buffer ;

I cannot make any changes to above code. The inc_factor is supposed to be able to take values from 0 to 255.

therefore in the function where a buffer is created, i do the following so as to ensure that the inc_factor is not negative:

Buffer* b_create(int init_capacity, char inc_factor,char o_mode){
    Buffer* buffer = (Buffer*)malloc(sizeof(Buffer));
    buffer->ca_head=(char*)malloc(sizeof(char)*init_capacity);

    buffer->inc_factor=(unsigned char)(inc_factor);

But the following line gives out a negative number:

printf("inc factor = %d",buffer->inc_factor);

What am I doing wrong here ? Plz Help.

  • 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-11T18:34:56+00:00Added an answer on June 11, 2026 at 6:34 pm

    You are formatting a signed variable as a signed value, so of course it will output a negative value if the variable exceeds 127. That is what happens when you store an unsigned value into a signed variable – it wraps around to the negative. If you cannot change the variable type itself, then you have to change how it is being formatted (type-casting a signed value to an unsigned type and then assigning to a signed variable is pointless):

    printf("inc factor = %u", (unsigned char) buffer->inc_factor); 
    

    Or:

    printf("inc factor = %d", (unsigned char) buffer->inc_factor); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a really irritating problem to have that springs from poor process, I
I have a really irritating problem with PHP on Windows Server 2008 R2. IIS
I really have problem with this one. So I have a jar with a
I have this situation that is really irritating me now. At random times with
I have really no idea why I'm asking this as this a really completely
Im new to iPhone development and I have really taken this to me. I
I'm using Filemaker Pro 12 Advanced. I have a few tables but have really
I really have no idea what I did to cause this exception, but I
I have really simple problem in my PHP script. There is a function defined
I have really been confused by this one. After pulling from a repo, I

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.