Simulating array_pop for various structures in C -
i new c working on project cannot work out how can needed.
i have 2 different struct arrays, differently defined , trying same action php's array_pop do, i.e. remove last element of array structure.
i know create 2 separate functions, 1 each structure type, not best idea, wondering whether possible can pass either structure type 1 function, , possibly flag, , flag determine type of structure should cast to.
my structures defined follows
typedef struct calllogsearchresultstruct { long date; int drowindex; } calllogsearchresultstruct; typedef struct calllogsearchdatastruct { char * date; char * time; char * bparty; char * aparty; float duration; char * cleardowncause; struct calllogsearchoutboundstruct * outboundlegs; } calllogsearchdatastruct;
below how structures initialised
calllogsearchdata = calloc(numrows, sizeof(calllogsearchdatastruct)); calllogsearch = calloc(numrows, sizeof(calllogsearchresultstruct));
numrows
being number of structs contain within array.
below how using structures
calllogsearchdata[datarow].aparty = null; calllogsearchdata[datarow].bparty = null; calllogsearchdata[datarow].cleardowncause = null; calllogsearchdata[datarow].date = null; calllogsearchdata[datarow].time = null; calllogsearchdata[datarow].outboundlegs = null;
apologise if simple straight forward answer, can't find on google, although not entirely sure called maybe i'm using wrong keywords.
thanks can provide.
what mean "remove"? how arrays allocated?
if have array created declaration such as:
struct foo my_foos[123];
there nothing can change fact my_foos
123 elements long. can of course select ignore of them having separate size_t foo_count
variable maintain.
arrays in c not dynamic (unlike lists/arrays in many more high-level languages). can implement dynamic array using malloc()
, not hard it's unclear if that's you've done.
Comments
Post a Comment