I have a pointer to the type of structure that I created. When the program starts, it starts as NULL, and then malloc / realloc, since I need to add / remove these structures, and I'm just going to use my pointer to point to the first structure and navigate it like an array.
When I malloc / realloc, I always make the size of the "array" / region in memory larger than necessary. I do this, so I can set the “last index” / memory region to NULL so that I can say something like while (pointer! = NULL).
I get an error: invalid lvalue value in assignment when I try to assign NULL to the last position in an array / memory area using strings:
connrhosts++;
remotelist = realloc(remotelist, sizeof(rhost)*(connrhosts + 1));
(remotelist + connrhosts) = NULL;
I think I say:
- It's time to add a new structure to my array so that I increase connrhosts by one.
- Rename the memory that is pointed to the remote system to a new memory area, which is the size of connrhosts (how many structures I will use), as well as one extra space so that I can make it NULL
- Delete points to a new memory area
- Use my pointer repeater and add connrhosts offsets that will now point to the last index of the memory region and make this pointer NULL.
As far as I can judge (or feel), I did everything right, but now I'm working on this project, and I get the impression that I have a tunnel vision. I would like a fresh set of eyes to look at my logic / code and make it clear what they think and what I did wrong. Thanks again: D
-
- , , .
:
typedef struct {
char address[128];
int port;
int conn;
int ofiles;
} rhost;
, , / , NULL, - . , while (NULL!= Remotelist). , , , , ? , /, , ? , - while (NULL!= * (Remotelist + someoffset))?
, / .
/ : rhost * remotelist = NULL;