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

  • Home
  • SEARCH
  • 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 654277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:28:37+00:00 2026-05-13T22:28:37+00:00

I have a pointer of a structure type that I made. On program start

  • 0

I have a pointer of a structure type that I made. On program start it begins as NULL and I then malloc/realloc as I need to add/remove these structures and I was just gonna use my pointer to point at the first structure and move through it like an array.

When I malloc/realloc I always make the size of the “array”/area in memory one larger than it needs to be. I do this so I can set the “last index”/area in memory to NULL so I can say something like while (pointer != NULL).

I get the error: invalid lvalue in assignment when I try to assign NULL to the last position in the array/area of memory with the lines:

  // Realloc remotelist by adding one to connrhosts
  connrhosts++;
  remotelist = realloc(remotelist, sizeof(rhost)*(connrhosts + 1));
  (remotelist + connrhosts) = NULL;

What I think I am saying is:

  • Its time to add a new structure to my array so I will increase connrhosts by one.
  • Realloc the memory that is pointed at remotelist to a new area of memory that is the size of connrhosts (how many structures I will use) as well as one additional space so I can make it NULL
  • Point remotelist to the new area of memory
  • Use my pointer remotelist and add the offset connrhosts which will now point to the last index of the area of memory and make that pointer NULL.

As far as I can tell (or feel) I did everything correctly, but I have been working on this project for sometime now and am under the impression I have tunnel vision. I would love to have a fresh set of eyes take a look at my logic/code and let me know what they think and what I did wrong. Thanks again. 😀

Edit –
Part of my problem is I think I have a misunderstanding of what I can do with pointers.

Here is my structure:

typedef struct {
  char address[128]; // Buffer that holds our address of the remote host
  int port; // Port of the remote host
  int conn; // FD to the connection of our remote host
  int ofiles; // Open files associated with the remote host
} rhost;

What I was hoping I could do was loop through my array/area of memory and say if its not NULL then do something with it. So my original loop statement is while (NULL != remotelist). Now I believe are reading responses and comments that this logic is wrong because I am checking if a pointer is null? I ought to be checking if the area of memory/structure that the pointer is pointing is null? If this is the case it ought to be something like while (NULL != *(remotelist + someoffset))?

I am doing it this way as my teacher suggested it/talked about it in class.

My initial declaration/initialization of remotelist was: rhost *remotelist = NULL;

  • 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-13T22:28:37+00:00Added an answer on May 13, 2026 at 10:28 pm

    Errornous lvalue assignments occur when the LHS is an evaluated expression that does not become a variable that can be assigned. What you’re doing looks like an operation (pointer arithmetic) which should be on the RHS.

    What you can do is:

    remotelist[connrhosts] = NULL;  // array notation asuming 
                                    // remotelist is an array of pointers
    

    assuming connrhosts is a int or size_t or you could do:

    remotelist += connrhost; // pointer arithmetic
    *remotelist = NULL; // assuming remotelist is an array of pointers.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 344k
  • Answers 344k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's a quick and dirty implementation. Hasn't been tested. NSString… May 14, 2026 at 5:42 am
  • Editorial Team
    Editorial Team added an answer The import statement has nothing to do with classloading -… May 14, 2026 at 5:42 am
  • Editorial Team
    Editorial Team added an answer Main advantage of serialize : it's specific to PHP, which… May 14, 2026 at 5:42 am

Related Questions

I'm in a situation where I'd like to instantiate an object of a type
I'd like to change the way some types are displayed using either 'dt' or
I notice that Swig provides a whole host of functions to allow for typecasting
I have a C function that takes a function pointer as argument, it's a
I am porting some C code to a TI DSP chip environment. I'm grappling

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.