I have this struct
typedef struct
{
int numberPipes; // |
int numberAmpersands; // &
int existsBiggerThan; // >
int existsLessThan; // <
int existsDoubleLargerThan; // >>
} lineData;
and I run in my loop on a char array (char*), in order to find all indexes of '&' and '|' .
I don’t know how much '&' and '|' I’m going to find . Is it possible to start with two arrays (using malloc)
of size 1 and enlarge them after each iteration , only if I find another occurrence of one of them ?
You can do that by calling
realloc.For performance reasons, it might be better to call it not for each new element, but once in X elements, so you reduce the number of calls to
malloc/realloc.